图像加载到浏览器很好,但是当我尝试写入一些文本,它的图像中断(像这样: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