HTML not parsing properly on image creation in php
I have to generate a magazine, got few records with exact path of images. Sort out all records in a string and now want to create a JPG or PNG file having the output of that string.
I used this code.
//set size of image
$pic = @imagecreatetruecolor(2835, 3898);
//setting text color
$text_color = imagecolorallocate($pic, 0, 0, 0); //black color
//setting bg color
$bgColor = imagecolorallocate($pic, 255,255,255); //white color
imagefill($pic , 0,0 , $bgColor);
//setting text with text color
imagestring($pic, 1, 5, 5, $output, $text_color);
//generating JPG
Imagepng($pic,$path."01.jpg");
开发者_如何学运维 //clearing image cache
ImageDestroy($pic);
Here $output is the string name.
It shows the html code of output values while the included images and backgrounds of divs are not appearing.
Can any one help me out in this regard.
thanks in advance
I think you need to set a header if you want to display the image or make it downloadable
set
header("Pragma: public"); // required
header("Content-Type: image/png");
header("Content-Disposition: attachment; filename=\"image.jpg;" );
header("Content-Transfer-Encoding: binary");
right before displaying the image
from php.net
imagestring() doesn't parse HTML
see http://ca2.php.net/manual/en/function.imagestring.php
The closest thing I can imagine to what you want would be to use the HTML2PDF library to generate a PDF and then use a PDF2TIFF tool to rasterize it, then convert the TIFF to whatever image format you want to actually output it as.
Or maybe you could use phpGTK / GTKWebKit to directly rasterize it. Basically you'd be writing a small browser in PHP.
精彩评论