PDA

View Full Version : url screenshot php



gloradin
05-06-2008, 04:07 PM
Hello,
I try to take url screenshots in php, and I try a script from php site with the fuction imagecreatefromjpeg, like this one:

<?
Header( "Content-Type: image/jpeg");
function LoadJPEG ($imgURL) {
##-- Get Image file from Port 80 --##
$fp = fopen($imgURL, "r");
$imageFile = fread ($fp, 3000000);
fclose($fp);
##-- Create a temporary file on disk --##
$tmpfname = tempnam ("/temp", "IMG");
##-- Put image data into the temp file --##
$fp = fopen($tmpfname, "w");
fwrite($fp, $imageFile);
fclose($fp);

##-- Load Image from Disk with GD library --##
$im = imagecreatefromjpeg ($tmpfname);

##-- Delete Temporary File --##
unlink($tmpfname);

##-- Check for errors --##
if (!$im) {
print "Could not create JPEG image $imgURL";
}
return $im;
}
$imageData = LoadJPEG("http://www.google.com");
imagejpeg($imageData, '', 100);
?>

But when I execute the script not appear any image contain the url screenshot.
If I execute the script in the script page (imagem_url.php) appear this phrase:"http://fotos.gloradin.com/experiencia/2/imagem_url.php".

If I call the image in other page don't appear anything, just a blank page.

I think I have to change something in the php.ini for authorize the image url capture, but I don't know what I have to change.

If the reason not is php.ini, what kind of problem my script have?

The best regards,
gloradin

goldensea80
05-10-2008, 07:07 PM
When I saw your post title, I was more than happy because someone can do it in PHP. However, your method is not correct, when you use fopen to open a URL, you will only get the HTML! How can you expect to get the actually rendered graphic of that webpage?

dug
05-23-2008, 04:21 AM
Uhhh... yes... what you are trying to do is waaaaaaaaaaaay more complex than that! What you are attempting is a screen grab of a page as it might be rendered in a web browser

Off the top of my head I'd be looking at piping a wget into some sort of screen capture ( standalone... not web based ) application, or running a dedicated box that can fire up an instance of a web browser and "snapshot" the url.

Alternative is to use one of those free site testing services that do a snapshot, and download the image from there... but usually there is a delay unless you give them $$.