Skip to content

Blurry screenshots #123

@crawlcars

Description

@crawlcars

If I try to take a screenshot of the following url, it comes out "blurry".

https://twitter.com/KeanuReevesoff1/status/1047128450547556353
21_09_22__1_54_40

Below is the code that I've written.

function takeScreenshotOfUrl(string $url, int $width = 400, int $height = 500): ?string {
$saveLocation = $SERVER['DOCUMENT_ROOT'] . '/screenshots/';
$fileName = date("y_m_d__G_i_s");
$counter = 0;
do {
$tempFileName = $fileName . ($counter > 0 ? "
" . $counter : "") . ".png";
++$counter;
} while (file_exists($tempFileName));
$fileName = $tempFileName;
unset($counter, $tempFileName);

  if ($height > 500)
        $height = 500;

  $screenCapture = new Capture($url);
  $screenCapture->setWidth($width);
  $screenCapture->setHeight($height);
  $screenCapture->setImageType('png');
  $screenCapture->setDelay(5000);
  $screenCapture->save($saveLocation . fileName);
  	
  if (file_exists($saveLocation . $fileName)) 
        return $fileName;
  return null;

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions