PHP:带有回声的图像不显示回声词,只显示图像


PHP: image with echo not showing the echo word just the image

脚本可以存储图像并将其显示在.php例如:

<?php
$im = imagecreatefrompng("test.png");
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>

我的问题是当我放类似的东西时

echo 'a word here';

它显示了图像,但回声部分没有显示。 对此有可能的解决方案吗? 就像我不想将图像脚本放入其他.php文件并在另一个.php脚本上读取它一样。我希望图像和回声在同一个脚本页面中。可能吗?

将标头设置为图像时,无法添加 echo 语句。

替代解决方案:不过,您可以使用PHP GD库在图像上写入文本。

<?php
echo 'hello world';
<img src="myimg.png" alt="yeehaw">