2017-07-07 48 views
0

我有兩個網站(同一臺服務器),其中一個簡單的矩形使用ImagickDraw繪製,它在一個做工精細,未能在第二位的錯誤 -ImagickDraw矩形 - 圖像無法顯示錯誤

圖像「 http://site_name/imagick/img?method=placeholder&params=258,150「無法顯示,因爲它包含錯誤。

基本上什麼代碼所做的就是它取methodparams從URL(高度&寬度)和繪製圖像。

$params = explode(",", $_GET["params"]); 
$width = (int) $params[0]; //258 
$height = (int) $params[1]; //150 

if ($method == "placeholder") { //This is true $method is set to placeholder 
    $image = new Imagick(); 
    $image->newImage($width, $height, "#707070"); 
    $image->setImageFormat("png"); 

    $x = 0; 
    $y = 0; 
    $size = 40; 
    $draw = new ImagickDraw(); 

    while ($y < $height) { 
    $draw->setFillColor("#808080"); 

    $points = array(
     array("x" => $x, "y" => $y), 
     array("x" => $x + $size, "y" => $y), 
     array("x" => $x + $size * 2, "y" => $y + $size), 
     array("x" => $x + $size * 2, "y" => $y + $size * 2), 
    ); 
    $draw->polygon($points); 

    $points = array(
     array("x" => $x, "y" => $y + $size), 
     array("x" => $x + $size, "y" => $y + $size * 2), 
     array("x" => $x, "y" => $y + $size * 2), 
    ); 
    $draw->polygon($points); 

    $x += $size * 2; 
    if ($x > $width) { 
     $x = 0; 
     $y += $size * 2; 
    } 
    } 

    $draw->setFillColor("#B0B0B0"); 
    $draw->setFontSize($width/5); 
    $draw->setFontWeight(800); 
    $draw->setGravity(Imagick::GRAVITY_CENTER); 
    $draw->annotation(0, 0, $width . " x " . $height); 

    $image->drawImage($draw); 

    header("Content-type: image/png"); 
    echo $image; 
} 

我檢查頭之前的緩衝區,它是空的也試過ob_clean() - 仍然無法正常工作。

檢查文件中的空白,因爲我發現它會影響圖像文件 - 但沒有空白。

任何想法可能是錯誤在這裏或無論如何跟蹤錯誤?

+0

也許檢查服務器日誌中是否有錯誤,或註釋掉'header'並查看瀏覽器中返回的內容。 – emcconville

+0

感謝您的評論,但錯誤是空白本身,發佈爲答案。 – jitendrapurohit

回答

0

這確實是空白,但不在同一個文件中(奇怪的奇怪怪異)。

檢查所有PHP文件包括與項目 -

include_once('file_name.php'); 

從多個文件,有一個這樣的文件,該文件<?php之前有一個空格(設置文件,其中包含了db_namebase url等)標籤。所以如果有人得到這個錯誤,請確保所有的php文件都是空白的。它會擾亂生成的png圖像。