我使用这个代码,如果我评论的行号“A”和“B”来创建图像
是否可以在PHP中使用动态生成的图像?
<?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);
?>
的代码工作的罚款和它产生在写有测试浏览器的图像。但我想要图像在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感谢您的建议。 –