Hi all,
I was wondering, can you still get a screenshot from a url using PHP and Google Pagespeed Insights, I've tried a few codes but I just get an empty file. Any help would be cool, thanks.
Hi all,
I was wondering, can you still get a screenshot from a url using PHP and Google Pagespeed Insights, I've tried a few codes but I just get an empty file. Any help would be cool, thanks.
You need to install a headless versison of Google Chrome on your web server.
This is the code that I use (Assume that $url is the website to take a screenshot of):
$hash = md5($url);
@shell_exec('timeout 15s /usr/bin/google-chrome --headless --screenshot="' . STATIC_PATH . '/images/screenshots/' . $hash . '.png" --window-size=1200,900 --disable-gpu --hide-scrollbars ' . escapeshellarg($url) . ' >> /dev/null 2>&1');
$screenshot_resource = imagecreatefrompng(STATIC_PATH . "/images/screenshots/$hash.png");
@unlink(STATIC_PATH . "/images/screenshots/$hash.png");We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.