圖像加載到瀏覽器很好,但是當我嘗試寫入一些文本,它的圖像中斷(像這樣:http://www.tradenepal.com.np/test.php)。當我註釋掉imagettftext()時,圖像不會再次加載。這發生在我的本地主機上,我使用WampServer版本2.5。我已經對inetrnet發表過如此多的評論,但我似乎無法知道問題所在。任何幫助將不勝感激。謝謝。我的代碼:PHP imagettftext()打破了圖像,如果我使用imagecreatefrompng,imagecreatefromjpeg和imagecreatefromgif
<?php
//Set content type
header('Content-type: image/jpeg');
// Create image from existing image
$jpgImage = imagecreatefromjpeg('file.jpg');
// Allocate color for text
$white = imagecolorallocate($jpgImage, 255, 255, 255);
// Set Path to Font File
$font = 'arialbd.ttf';
// Text to print to image
$text = 'Testing text output';
// Print Text On Image
imagettftext($jpgImage, 75, 0, 50, 400, $white, $font, $text);
// Send Image to Browser
imagejpeg($jpgImage);
// Clear Memory
imagedestroy($jpgImage);
?>
首先檢查圖像是否足夠大,以便將測試放置在已定位的位置。其次檢查'arialbd.ttf'文件是否正確地位於您指定的位置。 – RiggsFolly 2015-01-01 15:19:10
謝謝RiggsFolly,在提問後我想到了。 – HazardPJ 2015-01-08 05:22:47