Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blurry screenshots #123

Open
crawlcars opened this issue Sep 22, 2021 · 0 comments
Open

Blurry screenshots #123

crawlcars opened this issue Sep 22, 2021 · 0 comments

Comments

@crawlcars
Copy link

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;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant