Php“imagettftext”返回null图像(不工作)

时间:2012-12-16 20:15:52

标签: php php-gd

我在localserver和在线网络服务器上进行测试......但是返回一个空图像......

检查退货结果...... http://s8.postimage.org/sthztzj5x/null_image.jpg

<?php
Set the content-type
header('Content-Type: image/png');
$im = imagecreatetruecolor(400, 30);
$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);
$text = 'Testing...';
$font = 'arial.ttf';
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
imagepng($im);
imagedestroy($im);
?>

2 个答案:

答案 0 :(得分:0)

此脚本的第二行导致PHP解析错误。像这样在它的前面添加双斜杠:

//设置内容类型

答案 1 :(得分:0)

这对我来说是正确的。

http://www.laprbass.com/RAY_temp_rameez.php

<?php // RAY_temp_rameez.php
error_reporting(E_ALL);

// Set the content-type
header('Content-Type: image/png');
$im = imagecreatetruecolor(400, 30);
$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);
$text = 'Testing...';
$font = 'fonts/verdanaz.ttf';
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
imagepng($im);
imagedestroy($im);