【发布时间】:2012-09-25 10:15:09
【问题描述】:
我有:
echo"
<div id=IwantToSaveThisWholeDivAsAnImage)>
<div id=OneOfMultipleDivs>
<table>multiple tables rendered here
</table>
</div>
</div>";
我已经尝试过(其中之一):
$html_code = "
<html>
<head>
<title>Image</title>
<style>
body {
font-family:verdana;
font-size:11px;
color:black
}
</style>
</head>
<body>
my tables here
</body>
</html>";
$img = imagecreate("300", "600");
$c = imagecolorallocate($img, 0, 0, 0);
$c2 = imagecolorallocate($img, 255, 255, 255);
imageline($img,0,0,300,600,$c);
imageline($img,300,0,0,600,$c2);
$white = imagecolorallocate($img, 255, 255, 255);
imagettftext($img, 9, 0, 1, 1, $white, "arial.tff", '$html_code');
header("Content-type: image/jpeg");
imagejpeg($img);
我不允许使用外部库。读到它可以用 GD 完成,但到目前为止我一直没有成功。 任何想法和帮助将不胜感激! UB
【问题讨论】:
-
我有点困惑。您是否尝试呈现实际的 html 文档并将其保存到 img?
-
是的。我有动态构建的 html,我正在尝试将其保存到图像中(与其他元素结合并最终创建一个 pdf)
-
为什么不允许你使用任何库?
-
所以这不是 php 的问题。 php 仅提供 html 源代码(服务器端)。渲染是浏览器问题(客户端)。见stackoverflow.com/questions/1952570/…
-
没有外部工具是不可能的。单独使用 PHP 甚至是不可能的。我使用 wkhtmltopdf 进行了成功的实验,可以对网站进行“截图”,然后您可以裁剪所需的部分。