使用 Painty 将 HTML 转为图像文件

发布于 2024-11-17 07:17:34 字数 310 浏览 2 评论 0原文

我正在使用画图。 http://www.rabuser.info/painty.php 到目前为止一切顺利。但我现在的问题是如何让它创建图像文件而不是将其输出到屏幕。事实上,我希望它能够在用户甚至不需要通过 AJAX 访问页面的情况下创建它。

最终,这就是它的流动方式。他们会去那里的个人资料。从那里它运行一些 ajax 并从我指定的一些 HTML 创建图像并在配置文件中显示该图像。他们还可以链接到该图像并展示它,因此我希望它成为一个文件。

I am using Painty. http://www.rabuser.info/painty.php So far so good. But my question is now how would I make it create the image file instead of outputting it to the screen. In fact I want it to create it without the user even going to the page maybe through AJAX.

In the end this is how it will flow. They will go to there profile. From there it run some ajax and create an image from some HTML i specified and display the image on there profile. They would also be able to link to this image and show it off hence the reason I want it to be a file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

善良天后 2024-11-24 07:17:34

之后 imagepng($im);你可以添加这一行:

imagejpeg($im, 'yoo.jpg', 75); //creates jpeg file at 75 percent quality

如果它仍然不起作用,那么:

在 $html=@$_GET['html']; 之后添加这一行:

 $html='<h1>Painty Heading</h1><hr/><p>Welcome<br /><b>Yo...</b></p><p align = right><img src="http://static.php.net/www.php.net/images/php.gif" align="right" /></p>';

并在 'font_path' => 之后$__SERVER["DOCUMENT_ROOT"],
添加这一行:

'font_path' => "./",

我还推荐这些字体:

'font' => "VeraMono.ttf",
'font_bold' => "VeraMoBd.ttf",

在 C:\Windows\fonts 中找到这些文件

After imagepng($im); you can add this line:

imagejpeg($im, 'yoo.jpg', 75); //creates jpeg file at 75 percent quality

if it still doesn;t work, then:

After $html=@$_GET['html']; add this line:

 $html='<h1>Painty Heading</h1><hr/><p>Welcome<br /><b>Yo...</b></p><p align = right><img src="http://static.php.net/www.php.net/images/php.gif" align="right" /></p>';

and after 'font_path' => $__SERVER["DOCUMENT_ROOT"],
add this line:

'font_path' => "./",

and i also recommend these fonts:

'font' => "VeraMono.ttf",
'font_bold' => "VeraMoBd.ttf",

find those files in C:\Windows\fonts

┼── 2024-11-24 07:17:34

嗯,Painty 应该生成图像。确保您已按照 Painty.php 的说明正确设置标头:

$config = array(
    'input' => $_GET['html'],
    'output' => "png",
    'width' => 400,
    'height' => 300,
    'font_path' => "./",
    'font' => "tahoma.ttf",
    'font_bold' => "tahoma.ttf",
    '' => ''
);
$str = $config['input'];
if(get_magic_quotes_gpc()) 
{
    $str = stripslashes($str);
}
$im = painty($str);
//Set header. secured from header injection.

最重要的部分:

header("Content-Type: image/".str_replace("\r\n", "", $config['output']));
imagepng($im);

header 命令告诉服务器将文件视为图像 - 甚至尽管它可能被命名为image-generator.php。如果您也将文件视为图像,应该没问题:

<a href="image-generator.php?username=foo&level=36&class=Demoman">
    <img src="image-generator.php?username=foo&level=36&class=Demoman" />
</a>

假设 image-generator.php 已设置为接受 $_POST 数据。然后 image-generator.php 根据该数据创建一个 HTML 文件并将其作为输入发送到 Painty。

祝你好运!

Well, Painty should be producing an image. Make sure you have set up your headers correctly, as per painty.php's instructions:

$config = array(
    'input' => $_GET['html'],
    'output' => "png",
    'width' => 400,
    'height' => 300,
    'font_path' => "./",
    'font' => "tahoma.ttf",
    'font_bold' => "tahoma.ttf",
    '' => ''
);
$str = $config['input'];
if(get_magic_quotes_gpc()) 
{
    $str = stripslashes($str);
}
$im = painty($str);
//Set header. secured from header injection.

Most important part:

header("Content-Type: image/".str_replace("\r\n", "", $config['output']));
imagepng($im);

The header command tells the server to treat the file as an image– even though it may be named image-generator.php. If you treat the file as an image as well, it should be fine:

<a href="image-generator.php?username=foo&level=36&class=Demoman">
    <img src="image-generator.php?username=foo&level=36&class=Demoman" />
</a>

This is assuming image-generator.php has been set up to accept $_POST data. Then image-generator.php creates an HTML file from that data and sends it to Painty as input.

Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文