【发布时间】:2021-12-20 18:37:55
【问题描述】:
我用imagestring 和 PHP 的文本创建了一个图像。我知道imagepng($image) 没有 $filepath 在网页中显示图像,但我想知道是否可以通过 HTML 显示图像(使用 div 和标签)而不通过imagepng() 将图像保存到文件中。
我在下面使用 PHP 代码:
<?php
$image = imagecreatetruecolor(100, 100);
$white = imagecolorallocate ($image,255,255,255);
$black = imagecolorallocate ($image,0,0,0);
imagefill($image,0,0,$white);
imagestring($image, 5, 31, 50, 'text', $black );
header('Content-Type: image/png');
imagepng($image);
#phpinfo();
?>
<!DOCTYPE html>
<html>
<div>
<!-- want to show image created by imagestring() here -->
</div>
</html>
【问题讨论】:
-
将图像生成器脚本创建为一个完全独立的脚本 - 称为
blah.php并在img标记中使用它 -<img src='blah.php' />? -
@ProfessorAbronsius 我想在同一个文件中执行此操作,不要使用 url 作为源路径
-
唉,你不能在同一个文件中输出 HTML 和类似的图像。
-
是否可以防止imagepng占用网页?