我使用這個代碼,如果我評論的行號「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感謝您的建議。 –