2012-12-16 77 views
-1

我已經測試上的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://stackoverflow.com/q/11900852/367456)和[PHP無效圖像和錯誤處理](http://stackoverflow.com/q/2574713/367456) – hakre

回答

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

這應該被編輯到你現有的答案和/或一個或另一個應該被刪除。 – Charles

+0

@Ray Paseur:我現在再次看到這一點。使用編輯工具有問題嗎?如果您不提供反饋或清理東西,您可能會看到一些降價和標誌。保重。 – hakre

+0

@RayPaseur,你應該發佈一個答案,糾正所有提出的問題(和存在的問題,需要修復,但沒有提出)。在極少數情況下,您可能想要展示兩個完全(*哲學*)不同的答案,並且可以單獨發佈它們。這不是其中之一。我想我在過去的一年裏看過它可能有十幾次,然後只是爲了*非常好的問題。這...這是一個糟糕的問題。 – Charles

0

此腳本的第二行會導致PHP解析錯誤。雙斜槓添加到它的面前是這樣的:

//設置內容類型