-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform.php
41 lines (40 loc) · 1.28 KB
/
form.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
class Capture
{
/**
* Capture web screenshot using google api.
*
* @param (string) $url Valid url
*
* @return blob
*/
public function snap($url)
{
//Url value should not empty and validate url
if (!empty($url) && filter_var($url, FILTER_VALIDATE_URL)) {
$curl_init = curl_init("http://webscreen.pl:3000/png/{$url}");
curl_setopt($curl_init, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl_init);
curl_close($curl_init);
//call Google PageSpeed Insights API
//decode json data
$googlepsdata = json_decode($response, true);
//screenshot data
$snap = $googlepsdata['screenshot']['data'];
$snap = str_replace(['_', '-'], ['/', '+'], $snap);return $snap;
} else {
return false;
}
}
}if (isset($_POST['submit']) && !empty($_POST['url'])) {
$snap = (new Capture())->snap($_POST['url']);
if ($snap)
echo "<img src=\"data:image/jpeg;base64,".$snap."\" />";
else
echo "Enter valid url";
}
?>
<form method="post" action="form.php" >
<p>Website URL: <input type="text" name="url" value="" /></p>
<input type="submit" name="submit" value="CAPTURE">
</form>