2014-06-08 27 views
0

我发现了这个话题:convert text to image in php我该如何调用创建图像功能?

我测试了Sourabh Shankar提供的代码。

当我将这段代码粘贴到一个新的空php文件中,并调整字体路径时,它就完美了!但是当我在标题('Content-type:image/png')之前或之后放置回显时,行的话,那所有的失败

有人可以提供我如何调用该图像制作者在HTML文件中的代码:

例如:

<span>Here comes the image</span> 
<?php [call function??] ?> 
<span>and here we continue with some HTML</span> 

我需要创建一个PHP函数如果是这样的话:

我该怎么办? 如果我回复这个:

imagepng($ im);

那么他不会执行

imagedestroy($ IM);

我不知道如何做到这一点

回答

1

链接到您的作品作为一个独立的文件中的PHP代码,这样,当它在浏览器发出请求,将发回的图像。将标题设置为

header('Content-type: image/png'); 

表示代码将返回浏览器解释为图像文件的内容,而不是HTML文件。

您无法使用PHP将文件直接输出为HTML。您需要在单独的文件中使用该代码,并将其链接到代码中图像的src标记。

1

您需要通过http从其他脚本获取图像。

<span>Here comes the image</span> 
<img src="/path/to/image_handler.php"/> 
<span>and here we continue with some HTML</span> 

其中image_handler.php - 你的PHP脚本:

<?php 
… 
header('Content-type: image/png'); 
imagepng($im); 

注:调用之前从来没有输出东西header