PHP – How to capture screenshot of website from URL with example

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 :

  1. <?php
  2. $websiteURL="http://www.onlinecode.org/";
  3. $api_response=file_get_contents("https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=$websiteURL&screenshot=true");
  4. //decode json data
  5. $result=json_decode($api_response, true);
  6. //screenshot data
  7. $screenshot=$result['screenshot']['data'];
  8. $screenshot=str_replace(array('_','-'),array('/','+'),$screenshot);
  9. //display screenshot image
  10. echo"<img src="data:image/jpeg;base64,".$screenshot."" />";
  11. ?>
<?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."" />";

?>
Show Demo

Label :

PHP

Google API

How To

API

Web Development

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

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

5  +  2  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US