Forked from jaseclamp/get webpage thumbnails from Google
Created
September 25, 2015 20:56
-
-
Save pixeline/a52fd3334ba491b17672 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//ini_set('display_errors',1); | |
//error_reporting(E_ALL | E_WARNING); | |
function is_valid_url($url){ | |
$url = filter_var($url, FILTER_SANITIZE_URL); | |
return filter_var($url, FILTER_VALIDATE_URL); | |
} | |
/* RUNTIME */ | |
$sites = is_valid_url($_GET['url']); | |
if($sites){ | |
$sites = preg_split('/\r\n|\r|\n/', $sites); | |
foreach($sites as $site) | |
{ | |
//cache it | |
/* | |
if ( !$image = apc_fetch( "thumbnail:".$site ) ) | |
{ | |
*/ | |
$image = file_get_contents("https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url=$site&screenshot=true"); | |
$image = json_decode($image, true); | |
//echo "<pre>"; print_r($image); die; | |
$image = $image['screenshot']['data']; | |
//apc_add("thumbnail:".$site, $image, 2400); | |
// } | |
$image = str_replace(array('_','-'),array('/','+'),$image); | |
echo "<img src=\"data:image/jpeg;base64,".$image."\" border='1' />"; | |
} | |
} | |
else{ | |
echo "Please provide a url."; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment