Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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' />";
}
?>
@skyyyme

This comment has been minimized.

Copy link

@skyyyme skyyyme commented Dec 13, 2015

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

@ayanev

This comment has been minimized.

Copy link

@ayanev ayanev commented Dec 17, 2015

skywebdeveloper, remove line 19 and 27.

@skizzar

This comment has been minimized.

Copy link

@skizzar skizzar commented Dec 30, 2015

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

@shanejones

This comment has been minimized.

Copy link

@shanejones shanejones commented Apr 14, 2016

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

@fachrulreza20

This comment has been minimized.

Copy link

@fachrulreza20 fachrulreza20 commented Jun 8, 2016

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

This comment has been minimized.

Copy link

@vneverz vneverz commented Jul 14, 2016

Thanks, can this get full webpage?

@atefBB

This comment has been minimized.

Copy link

@atefBB atefBB commented Dec 14, 2016

Great idea! Thx !

@amidevelopment

This comment has been minimized.

Copy link

@amidevelopment amidevelopment commented Dec 29, 2016

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

This comment has been minimized.

Copy link

@jacknab jacknab commented Feb 10, 2017

does this no longer work?

@sassoon12

This comment has been minimized.

Copy link

@sassoon12 sassoon12 commented Feb 21, 2017

How can I download the image ?

@senocak

This comment has been minimized.

Copy link

@senocak 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

This comment has been minimized.

Copy link

@moreirapontocom moreirapontocom commented Apr 10, 2018

Very useful! Thank you.

@musabibnusiraj

This comment has been minimized.

Copy link

@musabibnusiraj musabibnusiraj commented Mar 4, 2019

how can i get full width and height?

@musabibnusiraj

This comment has been minimized.

Copy link

@musabibnusiraj musabibnusiraj commented Mar 4, 2019

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");
}

@musabibnusiraj

This comment has been minimized.

Copy link

@musabibnusiraj musabibnusiraj 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

@musabibnusiraj

This comment has been minimized.

Copy link

@musabibnusiraj musabibnusiraj commented Mar 4, 2019

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

This comment has been minimized.

Copy link

@AppWerft AppWerft commented Nov 18, 2019

Or you install the apc package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.