Usually to take a picture of our screen using the "Print Screen" or "Print Sc" button and there are also other applications. But here I will give a tutorial how to create a PHP program to capture the website screen using "URL".
The function of web page screen capture is used for various purposes in web applications.
Actually there is an awful lot available to take the screen of a website page, but we want to create our own program through PHP API and Google PageSpeed Insights.
Input form is useful to enter URL website address, While Form submit function to update URL address into picture with PHP.
<!DOCTYPE html>
<html>
<head>
<title> How to capture website screens via URL and using Google API (in PHP)</title>
</head>
<body>
<form method="post" action="screenshot.php">
<p>
Enter the Site URL : <input type="text" name="url" placeholder="site address....." />
</p>
<input type="submit" name="submit" value="CAPTURE SCREEN">
</body>
</html>
<style type="text/css">
html{
background-color: #c0c3c1;
}
input[type=text]{
width:50%;
padding: 15px 20px;
border: none;
border-radius:2px;
}
input[type=submit]{
width: 30%;
padding: 12px 25px;
margin: 8px 435px;
box-sizing: border-box;
font-family: sans-serif;
background-color: #4CAF50;
color: white;
border-radius:2px;
}
p{
text-align: center;
font-size: 20px;
font-family: sans-serif;
}
</style>
<?php
if (!empty($_POST['url'])) {
$siteURL = $_POST['url'];
if (filter_var($siteURL, FILTER_VALIDATE_URL)) {
$process = file_get_contents("https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=$siteURL&screenshot=true");
$process = json_decode($process, true);
$screenshot = $process['screenshot']['data'];
$screenshot = str_replace(array(
'_',
'-'
), array(
'/',
'+'
), $screenshot);
echo "<img src=\"data:image/jpeg;base64," . $screenshot . "\" />";
} else {
echo "Please enter a valid URL.";
}
}
?>
call the Google PageSpeed Insights API
data decode json
It serves to take the website screen
Serves to display the screen that has been captured
Code Via Drive : Download