How to Capture screenshot of website from URL using PHP?

Today now , in this post i will give you an example of how to get screen shot from any given URL by using PHP curl. We know there are several website is provide API for the capture website screenshot image by using their API Secret and Key.

Now in this example i am using the screenshotmachine.com website API. So this website provide us very simple way to user their API. If you haven’t account on the screenshotmachine.com then you must need to create a new account and get the Account Key. So we need to just copy that key.

So here i also use the variable “$accountKey”, you need to just assign on key on that variable. Now it is very simple an example and by using only simple file.

Also need to make sure we have a images folder in our root path with the full permission. So all images will download and then store on that table.

URL
https://www.youtube.com/watch?v=UdijbfMorUI
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>

Read Also: How to implement infinite ajax scroll pagination in Laravel?

Thanks for read. I hope it help you. For more you can follow us on facebook

Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.