Forum Moderators: coopster

Message Too Old, No Replies

Conver HTML to Image

website's homepage thumbshots

         

ebizcamp

9:40 pm on May 25, 2004 (gmt 0)

10+ Year Member



Hi,

I know there is a open source software (working in Lunix) can convert HTML file into PDF but Is there program (working in Lunix) can convert HTML page into imge (PNG,GIF,JPEG)?

Thanks

venelin13

6:41 am on May 26, 2004 (gmt 0)

10+ Year Member



Well, basicly you can do it in a few lines of code. You just need to be sure you have GD library installed at your server. Here is the code I just created:


<?
//put your html code here
$html_code = "
<html>
<head>
<title>My test title</title>
<style>
body {
font-family:verdana;
font-size:11px;
color:black
}
</style>
</head>
<body>
this is the body
</body>
</html>";

# Create the image
$img = imagecreate("300", "600");
imagecolorallocate($img,0,0,0);
$c = imagecolorallocate($img,70,70,70);
imageline($img,0,0,300,600,$c2);
imageline($img,300,0,0,600,$c2);

$white = imagecolorallocate($img, 255, 255, 255);
imagettftext($img, 9, 0, 1, 1, $white, "VERDANA.TTF", $html_code);

# Display the image
header("Content-type: image/jpeg");
imagejpeg($img);

?>

The result is here [php-developers.net]

Regarding the font type - I just take the verdata.ttf from my computer and uploaded to the server.

Hint: do not use "\t", but just put a few blank spaces. Else, you will see some bad symbols at the result image.

May be you can get some better results if you consult the php manual about imagecreate functions.

NickCoons

7:08 am on May 26, 2004 (gmt 0)

10+ Year Member



venelin13,

I think ebizcamp wants to take the processed HTML and images in the way that they'd be viewed in a browser and capture that to an image, not the HTML code itself.

venelin13

10:13 am on May 26, 2004 (gmt 0)

10+ Year Member



So you think he want to make a snapshot with PHP? I think it is impossible.

stuartc1

11:12 am on May 26, 2004 (gmt 0)

10+ Year Member



Hi,

Maybe youre looking for the opensource project called 'thumbshots'.

ebizcamp

5:10 pm on May 26, 2004 (gmt 0)

10+ Year Member



Thanks all of you for replies. I come to realize it is very hard to do it. Either call IE (in Windows) or Mozilia (in Linux) and "print" the page or write own browser. The 1st is slow and resource intensive while the 2nd is very hard.

Thumbshots.org does provide free thumbshots for DMOZ website but not free for non-DMOZ website. But I now think a 25$/month price is a better bargain than to hire people write codes implementing that function.