Capture page screenshot by URL PHP script
There are many third-party API available to capture screenshot of a page or website. For this I will used simple API `Google PageSpeed Insights API`, which is used to measure the performance of website. It will create a website screenshot when user try to check performance of any website. I will used file_get_contents() function in php to capture website screenshot. Website or page URL is required to pass in this function as a parameter. Use below code to take a website or page screenshot. Replace $URL variable value with your website link which you want to capture.
<?php//page or website URL which you wants to capture$siteURL = "phpesperto.com";$jsonData = file_get_contents("https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=$siteURL&screenshot=true");//decode $jsonData json data$jsonData = json_decode($jsonData, true);//Website data in array $jsonData// Image data key is in $jsonData['screenshot']['data'];$screenshot = $jsonData['screenshot']['data'];
//change some characters$screenshot = str_replace(array('_','-'),array('/','+'),$screenshot);
//pass image data in img srcecho "<img src=\"data:image/jpeg;base64,".$screenshot."\" />";?>
There are many third-party API available to capture screenshot of a page or website. For this I will used simple API `Google PageSpeed Insights API`, which is used to measure the performance of website. It will create a website screenshot when user try to check performance of any website. I will used file_get_contents() function in php to capture website screenshot. Website or page URL is required to pass in this function as a parameter. Use below code to take a website or page screenshot. Replace $URL variable value with your website link which you want to capture.
<?php//page or website URL which you wants to capture$siteURL = "phpesperto.com";$jsonData = file_get_contents("https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=$siteURL&screenshot=true");//decode $jsonData json data$jsonData = json_decode($jsonData, true);//Website data in array $jsonData// Image data key is in $jsonData['screenshot']['data'];$screenshot = $jsonData['screenshot']['data'];
//change some characters$screenshot = str_replace(array('_','-'),array('/','+'),$screenshot);
//pass image data in img srcecho "<img src=\"data:image/jpeg;base64,".$screenshot."\" />";?>
Recommanded Articles
- Get Facebook long live access token in AWS Lambda function
- How to make image background transparent using PHP
- Paypal credit card payment on website in PHP
- Capture page screenshot by URL PHP script
- How to get all UK addresses by postal code
- API versioning in Laravel App
- Get all the lists from Mailchimp account using CURL
- Create a LEAD in ZOHO CRM using Node JS
- Create a LEAD in ZOHO CRM using API
- Add new subscriber in a Klaviyo list API

Latest Comments
David Richard
20 Dec 2020Daniel rikson
21 Dec 2020