Saturday, September 16, 2017

PHP Script to Capture Screenshot of Website from URL

PHP Script to Capture Screenshot of Website from URL

In this article you will learn about Google PageSpeed Insights API. Generally, Google PageSpeed Insights API is used to measure the performance of a web page. But you can also use Google PageSpeed Insights API to get a screenshot of the website from URL.

Also you can use this script depending upon your requirement. Mostly you have seen this script in various google product, if you remember while sending the bug report it is automatically capture the web page screenshot.

Lets follow the below steps to capture screenshot of webpage :

Screenshot.php

<?php
   //enter your website url
   $siteURL = "http://www.skptricks.tk/";
   
   //call Google PageSpeed Insights API
   $googlePagespeedData = file_get_contents("https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=$siteURL&screenshot=true");
   
   //decode json data
   $googlePagespeedData = json_decode($googlePagespeedData, true);
   
   //screenshot data
   $screenshot = $googlePagespeedData['screenshot']['data'];
   $screenshot = str_replace(array('_','-'),array('/','+'),$screenshot); 
   
   //display screenshot image
   echo "<img src=\"data:image/jpeg;base64,".$screenshot."\" />";
   
   ?>

Output :
----------------
PHP Script to Capture Screenshot of Website from URL




No comments:

Post a Comment