How to Capture Screenshot of a Website Using PHP

Capturing website using PHP script is very easy. In this post, explain you how to capture screenshot using PHP code. We are using an PHP class “screenshot.class.php”. It will send an web request to ScreenshotLayer API to grab the website screenshot in JPG, GIF or PNG formats.

Steps to Capture Website Screenshot Using PHP Script

capture website screenshot using php

Get ScreenshotLayer API key:

Now you need the api key to access this class code. Using this api key an HTTP request send to screenshotLayer service to capture the screen.

To get api key SignUp here: https://screenshotlayer.com/product

Use ScreenShotLayer Php Class code:

Use below screenshot.class.php code. Just use you own API-KEY in this file and include this file in your screen capture sample.php file.

Write PHP code to Capture Screen

You just write code for use this api call to take the website screenshot. Follow below “sample.php” file code for this.

Just get both files and upload it on website accessible location. Firstly image take some time capture. This api store your image for 30 days only untill you capture again.

You can also check complete ScreenshotLayer API documentation here: https://screenshotlayer.com/documentation. Implement any api method as  per your need. Its quite easy to implement this PHP code to Capture Web Screenshot.

Download Script

Recommended Posts For You

About Harish

I am professional web developer and blogger. Use this blog to share own api and other web development experience with you. I do accept paid work. Write to me at - [email protected]

View all posts by Harish

1 thought on “How to Capture Screenshot of a Website Using PHP”

  1. An interesting example, but you can just get by with one function, something like this:
    function SiteScreenshot($token, $url, $width, $height, $response_type = ‘image’) {
    // Parameters.
    $token = $token; ///YOUR_API_TOKEN
    $url = urlencode($url);
    $width = $width;
    $height = $height;
    $response_type = $response_type; ///Response type: json, image

    // Create the query URL.
    $query = “https://api.pikwy.com/”;
    $query .= “?token=$token&url=$url&width=$width&height=$height&response_type=$response_type”;

    // Call the API.
    $image = file_get_contents($query);

    // Store the screenshot image.
    file_put_contents(‘./screenshot.png’, $image);
    }

Leave a Comment

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