Skip to content

Instantly share code, notes, and snippets.

@jaseclamp
Created July 17, 2014 02:36
Show Gist options
  • Star 35 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
  • Save jaseclamp/d4ac6205db352e822ff6 to your computer and use it in GitHub Desktop.
Save jaseclamp/d4ac6205db352e822ff6 to your computer and use it in GitHub Desktop.
<?php
$sites = "http://www.broadcastsolutions.com.au/
http://www.kvm.com.au/
http://www.ambertech.com.au/";
$sites = preg_split('/\r\n|\r|\n/', $sites);
echo "
<style>
img {float: left; margin: 15px; }
</style>
";
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' />";
}
?>
@AkashKrx
Copy link

Fatal error: Call to undefined function apc_fetch() in D:\Local server\htdocs\localhost\datsun\test\test.php on line 19

@ayanev
Copy link

ayanev commented Dec 17, 2015

skywebdeveloper, remove line 19 and 27.

@skizzar
Copy link

skizzar commented Dec 30, 2015

This is excellent!! Any way to make it grab a larger screenshot?

@shanejones
Copy link

Brilliant, Just what I needed! Upvoted your comment on SO too

@fachrulreza20
Copy link

Wow. Thanks.
How to generate the Image to the file and get the file name ?
or
How to combine the Image to the Facebook Feed Dialog ?

@vneverz
Copy link

vneverz commented Jul 14, 2016

Thanks, can this get full webpage?

@atefBB
Copy link

atefBB commented Dec 14, 2016

Great idea! Thx !

@amidevelopment
Copy link

Excellent resource,
I'm having an issue, it returns an error 'cause the & is been converted to & anyone else is having the same issue?
Thanks in advance

@jacknab
Copy link

jacknab commented Feb 10, 2017

does this no longer work?

@sassoon12
Copy link

How can I download the image ?

@senocak
Copy link

senocak commented Jun 8, 2017

Fatal error: Call to undefined function apc_fetch() in F:\xampp\htdocs\cv\a.php on line 19

How am i supposed to solve this ?

@moreirapontocom
Copy link

Very useful! Thank you.

@musabibnsiraj
Copy link

how can i get full width and height?

@musabibnsiraj
Copy link

How can I download the image ?

$rute = "img/pic.jpeg";

// decode base64
$pdf_b64 = base64_decode($screenshot);

// you record the file in existing folder

if(file_put_contents($rute, $pdf_b64)){
header("Content-type:image/jpeg");
}

@musabibnsiraj
Copy link

musabibnsiraj commented Mar 4, 2019

Fatal error: Call to undefined function apc_fetch() in F:\xampp\htdocs\cv\a.php on line 19

How am i supposed to solve this ?

### code be like below

//if ( !$image = apc_fetch( "thumbnail:".$site ) ) >>remove

	$image = file_get_contents("https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url=$site&screenshot=true");
	$image = json_decode($image, true); 			
	$image = $image['screenshot']['data'];

// apc_add("thumbnail:".$site, $image, 2400); >> remove

@musabibnsiraj
Copy link

Fatal error: Call to undefined function apc_fetch() in D:\Local server\htdocs\localhost\datsun\test\test.php on line 19

### code be like below

//if ( !$image = apc_fetch( "thumbnail:".$site ) ) >>remove

	$image = file_get_contents("https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url=$site&screenshot=true");
	$image = json_decode($image, true); 			
	$image = $image['screenshot']['data'];

// apc_add("thumbnail:".$site, $image, 2400); >> remove

@AppWerft
Copy link

Or you install the apc package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment