![]() ![]() How to Save Money on Your Cell Phone Bill.How to Free Up Space on Your iPhone or iPad.How to Block Robotexts and Spam Messages.Save base64 data in a file and save the screenshot as an image using PHP file_put_contents() function.Get domain name from website URL and use the domain as the output screenshot file name.Retrieve screenshot image data of the website using PHP.Call the Google PageSpeed Insights API and fetch data with PHP file_get_contents() function.Validate input value to check whether the given URL is valid using PHP FILTER_VALIDATE_URL Filter.This server-side script handles the screenshot capture process with Google PageSpeed Insights API using PHP. On form submission, the input value is posted to the server-side script ( getScreenshot.php) to handle the screenshot capture process with PHP.įetch and Save Screenshot with PHP (getScreenshot.php): The HTML form has one input field which accepts the URL of the website. In this example script, we will show how you can build a form to get website screenshot by the URL provided by the user and display the web page screenshot to the user. $screenshot_data = base64_decode ( $screenshot_data ) įile_put_contents ( $output_file, $screenshot_data ) Capture Website Screenshot from URL List(, $screenshot_data ) = explode ( ',', $screenshot_data ) List( $type, $screenshot_data ) = explode ( ' ', $screenshot_data ) Use PHP file_put_contents() function to create image file and write base64 data in it.You can also save website screenshot as an image on the server with PHP. $googlePagespeedData = json_decode ( $googlePagespeedData, true ) $googlePagespeedData = file_get_contents ( " $siteURL &screenshot=true&key= $googleApiKey " ) screenshot – Set it to true to retrieve the screenshot data.Some of the required parameters are given below. The Google API key should be appended in the query parameter to all request URLs. We will use Google PageSpeed Insights API to take screenshots of the website using PHP. The following code snippet helps to take a screenshot of the website by the URL and display it as a snapshot preview image. The API key will be created and a dialog will appear with the newly created API key.Ĭopy the API key for later use in the script on Google PageSpeed Insights API request. ![]() In the Credentials page, select Create credentials » API key.In the sidebar, select Credentials under the APIs & Services section.Click the ENABLE button to make the PageSpeed Insights API Library available.Search for the PageSpeed Insights API service in the API list and select PageSpeed Insights API.In the sidebar, select Library under the APIs & Services section. ![]() If you don’t have an existing project, create a new one. Select the project from the Project drop-down menu at the top.You need to attach the API key to the URL of the Google PageSpeed Insights API.īefore getting started, follow the below steps to enable the PageSpeed Insights API library and create an API key. ![]() Create Google API KeyĪn API key is required to authenticate with Google PageSpeed Insights API. The example script is designed to capture screenshots of the website or any online web pages with PHP. In this tutorial, we will explain how to capture a screenshot of the website from URL using PageSpeed Insights API and PHP. But you can also use Google PageSpeed Insights API to get a screenshot of the website from the URL. Generally, Google PageSpeed Insights API is used to measure the performance of a web page. If you wish to build your own script to get a screenshot from URL, you can do it easily using PHP and Google PageSpeed Insights API. There are various third-party APIs are available to take screenshots of the website. When website URLs are required to list on the web page, displaying website screenshots as a preview will provide a great user interface. Mostly, the website screenshot is used to display a preview of a web page. Web page screenshot capture functionality is used for various purposes in the web application. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |