我已經測試上的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);
?>
你不檢查那些*返回值的任何*。其中一項功能可能失敗。註釋掉'header'調用,添加'error_reporting(-1); ini_set('display_errors',true);'然後重試。我敢打賭,你會看到一個巨大的PHP錯誤,警告或通知。 – Charles
您需要在PHP中啓用錯誤日誌記錄(記錄非常重要,因爲圖像不會向您顯示文本)。將報告設置爲最高級別。然後按照錯誤日誌,它會告訴你錯誤在哪裏。另請參見[我如何使用打印調試PHP圖像?](http://stackoverflow.com/q/11900852/367456)和[PHP無效圖像和錯誤處理](http://stackoverflow.com/q/2574713/367456) – hakre