Page 1 of 1
Webpages to PNg/Jpg/Gif/BMP
Posted: Wed Aug 16, 2006 8:02 am
by ahsanra
Hi,
Is there a way to convert a piece of HTML/webpage to a PNg/JPG/GIF/BMP format.
How can we do that in PHP?
waiting for your response.
Thanks
Posted: Wed Aug 16, 2006 8:03 am
by JayBird
Its been discussed before. Search this forum for "screenshot"
Posted: Sat Aug 19, 2006 7:32 pm
by R4000
Grab yourself a copy of IECapt...
Then use this little script.
http://iecapt.sourceforge.net/
Code: Select all
<?php
/**
* IECapt - PHP Frontend.
* -
* IECapt is a small application designed for screengrabbing websites
* Using the Internet Explorer rendering engine.
* -
* This frontend is designed to allow people to enter URLs online
* and be thrown a screenshot (resized to required dimensions) back
* -
* This code is COPYRIGHT (c) 2006, Peter Corcoran. ALL RIGHTS RESERVED.
* ANY UNLICENSED USAGE WILL BE PUNISHED TO THE FULL EXTENT OF THE LAW.
**/
?>
<html>
<head>
<title>IECapt - Frontend</title>
<style>
* {
font-family: verdana;
font-size: 10px;
}
</style>
</head>
<body>
<?php
/**
* Okay, we will certainly go over the 30 second time limit.
* So we need to get rid of it. UNLIMITED TIME!!! :P
**/
set_time_limit(0);
/**
* If we had a URL posted...
**/
if($_POST['url']) {
/**
* This URL is going to end up in the shell.
* So we need to make it safe!
**/
$f = escapeshellcmd($_POST['url']);
/**
* Notify the user that we are working on creating the thumbnail
**/
echo " Attempting to create thumb... Please wait<br />\n";
/**
* Flush the output buffer.
* -> This is for stupid browsers that won't display text till 100% loaded
**/
flush();
/**
* Lets start creating that thumbnail
* -> This step takes a LONG time.
**/
shell_exec("IECapt.exe \"" . $f . "\" " . md5($f) . ".png");
/**
* Okay, the max width was sent to us via _POST
* and the max height doesn't exist, so make it big.
**/
$maxw = (int)$_POST['maxw'];
$maxh = 10000;
/**
* We need to resize what the IECapt generated now...
* -> So lets load it!
**/
$im = imagecreatefrompng(md5($f) . ".png");
/**
* Lets find out how big the image, that IECapt got, is...
**/
$w = ImageSX($im);
$h = ImageSY($im);
/**
* Now resize that baby!
* -> Thank you Alex Poole :)
**/
list($image) = resizeImage($im, $w, $h, $maxw, $maxh);
/**
* Resized... lets throw it back where it came from.
**/
imagepng($image, md5($f) . ".png");
/**
* And let the user know we have finished.
**/
echo " Created!<br /><img src=\"" . md5($f) . ".png\" />\n";
/**
* End If
**/
}
/**
* Output HTML
**/
?>
<form actiom="thumb.php" method="POST">
<table>
<tr><td>URL to Thumb: </td><td><input type="text" name="url" /> </td></tr>
<tr><td>Maximum Width:</td><td><input name="maxw" value="300" /> </td></tr>
<tr><td> </td><td><input type="submit" value="ThumbIT!" /></td></tr>
</table>
</form>
</body>
</html>
<?php
/**
* resizeImage
* -
* A small function by Alex Poole for resizing images
**/
function resizeImage($image, $iw, $ih, $maxw, $maxh) {
if ($iw > $maxw || $ih > $maxh){
if ($iw>$maxw && $ih<=$maxh){
$proportion=($maxw*100)/$iw;
$neww=$maxw;
$newh=ceil(($ih*$proportion)/100);
} else if ($iw<=$maxw && $ih>$maxh){
$proportion=($maxh*100)/$ih;
$newh=$maxh;
$neww=ceil(($iw*$proportion)/100);
} else {
if ($iw/$maxw > $ih/$maxh){
$proportion=($maxw*100)/$iw;
$neww=$maxw;
$newh=ceil(($ih*$proportion)/100);
} else {
$proportion=($maxh*100)/$ih;
$newh=$maxh;
$neww=ceil(($iw*$proportion)/100);
}
}
} else {
$neww=$iw;
$newh=$ih;
}
if (function_exists("imagecreatetruecolor")){
$newImage=imagecreatetruecolor($neww, $newh);
imagecopyresampled($newImage, $image, 0,0,0,0, $neww, $newh, $iw, $ih);
} else {
$newImage=imagecreate($neww, $newh);
imagecopyresized($newImage, $image, 0,0,0,0, $neww, $newh, $iw, $ih);
}
return Array($newImage, $neww, $newh);
}
?>
Posted: Sun Aug 20, 2006 6:25 am
by ahsanra
well this utility is for windows server and i am using LINUX server.
i need a solution that works with php and linux.
Thanks
Posted: Sun Aug 20, 2006 2:04 pm
by nickvd
I'd be interested in this as well. I'm currently using a firefox extension to acomplish this task manually, it's a real pita when we have hundreds of client sites we'd like a full screenshot for..
Posted: Sun Aug 20, 2006 2:30 pm
by feyd
Port Gecko to PHP.

Posted: Sun Aug 20, 2006 2:47 pm
by nickvd

I'll get right on that
Though, on that note, the extension uses java to get the screenshots (i havn't had a chance to look thru the extension), so I'm thinking that there must be some way to either modify the extension, or use php to access the java part of the code /somehow/ and get the image data I'm looking at...
Using:
http://andy.5263.org/screengrab/
Posted: Mon Aug 21, 2006 1:28 pm
by R4000
I 'pose it wouldn't be too hard to make:
http://khtml2png.sourceforge.net/
work on a server, then use something like the code I posted about to create the screens.