screen icon indicating copy to clipboard operation
screen copied to clipboard

Blurry screenshots

Open crawlcars opened this issue 3 years ago • 0 comments

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;

}

crawlcars avatar Sep 22 '21 02:09 crawlcars