我有一個類可以渲染圖像的幾個函數。用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