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

问题描述:

我已经测试上的LocalServer和在线网络服务器...但返回一个空的图片PHP “imagettftext” 返回null图像(不工作)

检查返回结果... 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); 
?> 
+0

你不检查那些*返回值的任何*。其中一项功能可能失败。注释掉'header'调用,添加'error_reporting(-1); ini_set('display_errors',true);'然后重试。我敢打赌,你会看到一个巨大的PHP错误,警告或通知。 – Charles

+0

您需要在PHP中启用错误日志记录(记录非常重要,因为图像不会向您显示文本)。将报告设置为*别。然后按照错误日志,它会告诉你错误在哪里。另请参见[我如何使用打印调试PHP图像?](http://*.com/q/11900852/367456)和[PHP无效图像和错误处理](http://*.com/q/2574713/367456) – hakre

这正确地为我工作。

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); 
+1

这应该被编辑到你现有的答案和/或一个或另一个应该被删除。 – Charles

+0

@Ray Paseur:我现在再次看到这一点。使用编辑工具有问题吗?如果您不提供反馈或清理东西,您可能会看到一些降价和标志。保重。 – hakre

+0

@RayPaseur,你应该发布一个答案,纠正所有提出的问题(和存在的问题,需要修复,但没有提出)。在极少数情况下,您可能想要展示两个完全(*哲学*)不同的答案,并且可以单独发布它们。这不是其中之一。我想我在过去的一年里看过它可能有十几次,然后只是为了*非常好的问题。这...这是一个糟糕的问题。 – Charles

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

//设置内容类型