imagePNG:如何将输出保存在变量中,然后使用 img 标记显示它


imagepng: how to save the output in a variable and then display it using img tag

我想将imagepng的输出保存到变量而不是支付它,然后想在img标签中使用变量来显示图像。我该怎么做?

我正在使用一个聪明的模板,

我需要将生成的图像保存到变量中,然后将其显示在一个聪明的模板 tpl 文件中

谢谢它提前

imagepng — 将 PNG 图像输出到浏览器或文件

尝试如下:

ob_start();
imagepng($png);
$imagedata = ob_get_contents();
ob_end_clean();
echo '<img src="data:image/png;base64,'.base64_encode($imagedata).'"/>';

尝试使用流。实现一个流包装器,该包装器将写入变量的内容保存,并将这种类型的流传递到 imagepng 中。

有关更多详细信息,请参阅图像输出。