You may have a requirement to show the website’ screenshot in certain pages. You can use some third-party paid services for that. But here
we are demonstrating a free service, that too from Google. You can write your own script to get the screenshot from URL.
Basically, Google PageSpeed Insights API is used to analyze the page speed/performance of your website. But you can use Google PageSpeed Insights API for getting the screenshot too.
The following example script takes a screenshot of the website by the URL and shows as an image.
How to get the screenshot of website from URL
Use the following code written in PHP to get the screenshot, as we utilize the Google Pagespeed API.
<?php //website url $siteURL = "https://www.tutsplanet.com/"; //call Google PageSpeed Insights API $gData = file_get_contents("https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=$siteURL&screenshot=true"); //decode json data $gData = json_decode($gData, true); //print_r($gData); //screenshot data $screenshot = $gData['screenshot']['data']; //$screenshot = str_replace(array('_','-'),array('/','+'),$screenshot); //display screenshot image echo "<img src=\"data:image/jpeg;base64,".$screenshot."\" />";