PHP Classes

convert html to image

Recommend this page to a friend!

      Top level forums  >  PHP Specialists  >  General  >  convert html to image  
Subject:convert html to image
Summary:convert html to image
Messages:1
Author:prabodh
Date:2012-07-24 08:36:42
Update:2012-07-24 09:57:02
 

  1. convert html to image   Reply   Report abuse  
Picture of prabodh prabodh - 2012-07-24 09:57:02

<?php


header("Content-type: image/jpeg");

$text = "
<h1>Here goes content</h1>
";

$padding = 10; #10px
$fsize = 12; #font size 12 pixels
$ttf ="./verdana.ttf"; #path to windows ttf font file
$size = imagettfbbox($fsize, 0, $ttf, $text);
$xsize = abs($size[0]) + abs($size[2])+($padding*2);
$ysize = abs($size[5]) + abs($size[1])+($padding*2);
$image = imagecreate($xsize, $ysize);
$white = imagecolorallocate ($image, 255, 255, 255);
$black = imagecolorallocate ($image, 0, 0, 0);
imagefilledrectangle ($image, 0, 0, $xsize, $ysize, $white);
$text_color = imagecolorallocate($image, 233, 14, 91);
imagettftext($image, $fsize, 0, $padding, $fsize+$padding, $black, $ttf, $text);
imagestring($image, 1, 5, 5, "<h2>A Simple Text String</h2>", $text_color);
imagejpeg($image,"./screenshot.gif",85); #85%quality
?>

I want to convert html to image. i have above code. but when i run above code it display error: the image cannot display because it contain error.

anybody can help me to debug this code.