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.
<!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>
Thanks for read. I hope it help you. For more you can follow us on facebook