我有一个类可以渲染图像的几个函数。用php渲染图像用html输出它<img>标签
// render.php
class Render {
public function Render($some_arguments) {
...
header("Content-Type: image/png");
$im = @imagecreate(110, 20)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
imagepng($im);
return "data:image/png;base64,".base64_encode($im);
}
}
然后我有一个包含HTML代码和我的PHP文件,我想输出的图像的< img>
标签内:
// index.php
include("render.php");
$render = new Render();
echo "<htlm><head></head><body>";
echo "<img src=\"".$render->Render(1)."\" />";
echo "</body></html>";
当我在浏览器中运行的index.php我只得到一个空白的屏幕。
我不能使用函数调用作为图像源吗?我知道我可以使用一个PHP文件作为源,如< img src="render_image.php" />
,但我不能以面向对象的方式发送任何参数(我知道我可以使用$ _GET来检索参数),但是我想用一个很好的对象面向对象的代码。
那么,有什么办法可以使用函数调用作为html标记的来源吗?
你应该得到无功能的垃圾,而不是一个空白屏幕。提高error_reporting或查看error.log。此外,' - > Render()'函数将输出img数据,而不是返回它。首先,而不是对象接口。 – mario