Sie sind hier : sebastian1012.bplaced.net/ homepage-neu / Kurze-Scripte-und-Codeschnipsel / index.php

Zurück


Der Quellcode dazu


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
<form method="post" action="snapshout-from-webseize.php" >
<p>Website URL: <input type="text" name="url" value="" /></p>
<input type="submit" name="submit" value="CAPTURE">
</form>
 
<?php
if(!empty($_POST['url'])){
    
//website url
    
$siteURL $_POST['url'];

    if(
filter_var($siteURLFILTER_VALIDATE_URL)){
        
//call Google PageSpeed Insights API
        
$googlePagespeedData file_get_contents("https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=$siteURL&screenshot=true");

        
//decode json data
        
$googlePagespeedData json_decode($googlePagespeedDatatrue);

        
//screenshot data
        
$screenshot $googlePagespeedData['screenshot']['data'];
        
$screenshot str_replace(array('_','-'),array('/','+'),$screenshot);
//http://image.thum.io/get/width/400/crop/800/http://www.google.com/
        //display screenshot image
        
echo "<img src=\"data:image/jpeg;base64,".$screenshot."\" />";
    }else{
        echo 
"Please enter a valid URL.";
    }
}
?>