【发布时间】:2011-10-25 07:35:43
【问题描述】:
我正在使用此代码创建图像
<?php
// Set the content-type
header('Content-Type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
(A)print ('<div class="test">');
imagepng($im);
print ('</div>');
(B)imagedestroy($im);
?>
如果我注释行号“A”和“B”,代码可以正常工作,它会在浏览器上生成带有测试的图像。但我希望图像位于 div 中。所以我取消注释 (A) 和 (B) 行,但它没有给出正确的输出。生成的html也奇怪生成的html是
<img src="http://localhost/php/test92.php" alt="The image “http://localhost/php/test92.php” cannot be displayed, because it contains errors.">
【问题讨论】:
-
您必须了解 HTML 是什么以及它是如何工作的。无意冒犯,只是一个友好的建议。
-
@Col.Shrapnel 感谢您的建议。