ItSolutionStuff.com

PHP Capture Screenshot of Website from URL Example

By Hardik Savani • May 14, 2024
PHP

Today, i am going to give you example of how to grab screen shot from given URL using PHP curl. There are several website provide API for capture website screenshot image using their API Secret and Key.

In this example i am using screenshotmachine.com website API. This website provide very simple way to user their API. If you haven't account on screenshotmachine.com then you must create new account and get Account Key. So you have to just copy that key.

I also use variable "$accountKey", you have to just assign that key on that variable. It is very simple example and using only simple file.

Make sure you have images folder in your root path with full permission. All images will download and store on that table.

URL

http://test.hd/?url=http://google.com

Index.php

<!DOCTYPE html>

<html>

<head>

<title>PHP - Capture screenshot of website from URL</title>

</head>

<body>

<?php

$image = time().'.png';

$accountKey = 'your Account Key';

$ch = curl_init('http://api.screenshotmachine.com/?key='.$accountKey.'&size=M&format=png&url='.$_GET['url']);

$fp = fopen('images/'.$image, 'wb');

curl_setopt($ch, CURLOPT_FILE, $fp);

curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);

curl_close($ch);

fclose($fp);

?>

<img src="images/<?php echo $image ?>" />

</body>

</html>

You can get more information from here : Screenshotmachine.

Tags: PHP
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

PHP CURL Post Request with Parameters Example

Read Now →

PHP JQuery Ajax Post Request Example

Read Now →

Dynamic Dependent Dropdown using VueJS and PHP

Read Now →

PHP MySQL Login with Google Account Example

Read Now →

PHP Ajax Multiple Image Upload with Preview Example

Read Now →

How to Create Zip Folder and Download in PHP?

Read Now →

PHP Bootstrap Autocomplete Tokenfield using Ajax Example

Read Now →

Multiple File Upload using Dropzone JS in PHP Example

Read Now →

How to Integrate Google Recaptcha with PHP Form?

Read Now →

PHP Crop Image Before Upload using Croppie JS Example

Read Now →

PHP JQuery Select2 Ajax Autocomplete Example

Read Now →

How to Remove Duplicate Values from Array in PHP?

Read Now →

How to Remove Null Values from Array in PHP?

Read Now →