2012-08-10 64 views
0

我想打印調試一個php生成的圖像算法。 問題是,它不會輸出我打印的文字。 如何輸出變量,以便我可以調試? 謝謝, Furtano如何用打印調試PHP圖像?

public function drawPicture() 
    { 
     $im = imagecolorallocate ($this->picture, 255, 0, 255); 
     imagettftext($this->picture, $this->fontSize , 0, 100, 100,$im , "cooperm.TTF", $this->name); 



     # int ImageCopy (resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h) 
     //imagecopy($this->picture, $this->pika, $this->wappen['pika']['dst_x'], $this->wappen['pika']['dst_y'], 0, 0, $this->pika_size[0], $this->pika_size[1]); 

     $zufall = rand(1,99999999); 

     #header("Content-Type: image/jpeg"); 
     imagepng($this->picture); 

     $this->checkFontSize(); 

     imagedestroy($this->picture); 

     print "WHY_DOESNT_PRINT?"; 


    } 
+1

打開錯誤報告上。在'print'語句之前,你的腳本可能會失敗。嘗試將'print'進一步移動到代碼中,甚至到函數的開頭,以確保它被調用。 – Bojangles 2012-08-10 11:39:28

+0

腳本不會失敗。多數民衆贊成我如何使用腳本打印''; – Furtano 2012-08-10 11:45:49

+0

你現在看到什麼?考慮到你註釋掉了頭文件函數的調用,但是你仍然在調用imagepng,你應該看到圖像源和你的文本後 – mishu 2012-08-10 11:53:36

回答

1

你發送的PNG圖片瀏覽器,所以瀏覽器試圖顯示圖像。額外的文字被視爲無效的圖像數據,因此不會顯示。

一個問題的解決方案將使用header()調用調試信息發送到您的瀏覽器,或使用Firefox + Firebug的+ PHP的螢火蟲適配器。 Firebug與標題一起傳輸信息,所以它在圖像生成功能中是安全的。

0

使用rorrorlog來調試您想要查看的腳本。 書面文件可以很容易地查看。

居:

error_log("\r\n debug " . implode("; ", $hc), 3, "errors.log"); // in case array 
error_log("\r\n print " . $im, 3, "errors.log");