从html创建图像


create image from html

我想从html创建一个图像,我不能使用油漆,因为它是过时的,不再工作,我想要类似的东西。我已经尝试使用GD库创建图像,像这样

<?php
$html_code = "<b> this is the body </b> "; 
// 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, "arial.ttf", $html_code); 
// Display the image 
header("Content-type: image/jpeg"); 
imagejpeg($img);

,但它不会"编译"HTML标签,并将它们作为文本打印到图像中。

GD库不具备呈现html代码并在图像上绘制的能力。如果你想绘制粗体文本,你需要使用粗体字体,例如arialbd.ttf

简短的回答是,没有浏览器就无法呈现HTML。

一个更长的答案是,你可以在浏览器中呈现HTML,但你不能轻易地自动捕获屏幕截图(有activeX小部件可以做到这一点,但activeX是一个坏主意)。一个更好的方法是使用HTML客户端,它可以呈现为合适的格式,例如xhtml2pdf,也有在线服务可用于此