How to Capture Screenshot of Website from URL using PHP Web Development

How to Capture Screenshot of Website from URL using PHP Web Development

Today in Web Development We will see How to Capture Screenshot of Website from URL using PHP.Web page screenshot capture functionality is used for various purposes in the web application. There are many third party APIs are available to take a screenshot of the website. But if you wish to build your own script to get a screenshot from URL, you can do it easily using PHP and 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. In this tutorial, we will show you how to capture a screenshot of the website from URL using Google PageSpeed Insights API and PHP.

The following example script takes a screenshot of the website by the URL and shows as an image.

How to Capture Screenshot of Website from URL using PHP

How to Capture Screenshot of Website from URL using PHP

Get Screenshot of Website from URL

To make web page snapshot, Google PageSpeed Insights API need to be called with the following params.

  • url: specify the URL of the website.
  • screenshot: specify screenshot=true to retrieve the screenshot data.

 

Capture Website Screenshot from URL

In this example script, we will show how you can build a form to get website screenshot by the URL provided by the user and display the web page screenshot to the user.

HTML:
The following HTML form has one input field which accepts URL of the website. On form submit the site URL is submitted to the PHP script to get the screenshot of the website.

 

PHP (getScreenshot.php):
Before calling the call Google PageSpeed Insights API, the submitted input value is validated to check whether it is a valid URL. The screenshot data is retrieved from the Google PageSpeed Insights API and screenshot image of the website is shown.

Conclusion

So that’s itHow to Capture Screenshot of Website from URL using PHP.If you like this tutorial script then share it with your community. If you have any suggestion Feel free to comment below.If you want to learn more about PHP, CodeIgniterAngularJSLaraveljQuery  Web Development then daily visit PHPCodify.Sharing is Caring.

Capture Screenshot of Website from URL using PHP

Read previous post:
POST and Receive JSON Data using PHP
How to POST and Receive JSON Data using PHP cURL Web Development

How to POST and Receive JSON Data using PHP cURL Web Development Today in Web Development Tutorial We learn How to...

Close