PHP – How to capture screenshot of website from URL with example
In this post we will give you information about PHP – How to capture screenshot of website from URL with example. Hear we will give you detail about PHP – How to capture screenshot of website from URL with exampleAnd how to use it also give you demo for it if it is necessary.
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.onlinecode.org/";
- $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."" />";
- ?>
<?php $websiteURL = "http://www.onlinecode.org/"; $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."" />"; ?>
Hope this code and post will helped you for implement PHP – How to capture screenshot of website from URL with example. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs