In this PHP Tutorial, I am going to tell you how to capture screenshot of any website from URL.
There are many third party APIs are available to capture screenshot of the website using PHP script.
In this example, I am using Google APIs to capture screenshot from given url.
You can easily capture the screenshot using Google APIs.
Screenshot is a visual element that meant for capturing what’s immediately visible on the browser.
There are many reason to capture screenshot to report any issues of the website to admin.
Sometimes you make any bank transactions and you want to save the details of that transaction, then there you can use this script to capture screenshot.
URL must be valid url with "http".
Example :
- <?php
- $websiteURL = "http://www.expertphp.in/";
- $api_response = file_get_contents("https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=$websiteURL&screenshot=true");
- //decode json data
- $result = json_decode($api_response, true);
- //screenshot data
- $screenshot = $result['screenshot']['data'];
- $screenshot = str_replace(array('_','-'),array('/','+'),$screenshot);
- //display screenshot image
- echo "<img src=\"data:image/jpeg;base64,".$screenshot."\" />";
- ?>