2011-04-04 110 views
1

我想調整上傳的圖像。我得到錯誤PHP圖像調整大小錯誤

Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file in /home/rumdood/lib/photograph.php on line 309

Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: '/home/rumdood/public_html/uploads/13018946005603.jpg' is not a valid JPEG file in /home/rumdood/lib/photograph.php on line 309

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/rumdood/lib/photograph.php on line 410

Warning: Cannot modify header information - headers already sent by (output started at /home/rumdood/lib/photograph.php:309) in /home/rumdood/application.php on line 22

而圖像沒有被調整大小。最後一個錯誤是由於標題功能。

管道309是這樣

$this->image['render'] = imagecreatefromjpeg($this->s_image); 

線410是這樣

imagecopyresampled($this->image['composite'], $this->image['render'], 
        0, 0, 0, 0, $new_width, $new_height, 
        $this->image['width'], $this->image['height']); 

我的PHP版本是PHP Version 5.2.6

我來自的phpinfo

GD Support   enabled 
GD Version   bundled (2.0.34 compatible) 
FreeType Support enabled 
FreeType Linkage with freetype 
FreeType Version 2.1.9 
GIF Read Support enabled 
GIF Create Support enabled 
JPG Support   enabled 
PNG Support   enabled 
WBMP Support  enabled 
XPM Support   enabled 
XBM Support   enabled 
+0

什麼是$ this-> s_image? – grc 2011-04-04 06:30:58

+0

沿線的某處$ this-> s_image未獲取數據填充,已損壞或不是jpg – 2011-04-04 06:32:28

+0

@grc多數民衆贊成的圖像的絕對文件路徑 – 2011-04-04 06:35:22

回答

4

由於@charles建議..這兩個錯誤是自explanitory

檢查有效圖像從

if($_FILES["userPicture"]["error"] == 0) { 
// File was uploaded ok, so it's ok to proceed with the filetype check. 
$uploaded_type = exif_imagetype($_FILES["userPicture"]["tmp_name"]); 
// What we have now is a number representing our file type. 

switch($uploaded_type) { 
    case "1": 
     $uploaded_type = "gif"; 
    break; 
    case "2": 
     $uploaded_type = "jpg"; 
    break; 
    case "3": 
     $uploaded_type = "png"; 
    break; 
} 

}


對於 imagecreatefromjpeg():GD-JPEG,libjpeg的:可恢復的錯誤:JPEG的提前結束

這是一個與php 5和gd2的問題。繼承人如何解決它

  • PHP 4:neccesarry它無需任何操作應該工作正常
  • PHP 5.0 - 5.1.2 =升級到最新的PHP 5
  • PHP 5.1.3 - 電流=聲明此變量在你的文件中打電話之前imagecreatefromjpeg()
  • ini_set('gd。jpeg_ignore_warning',1);

不能在頁面的頂部修改標題信息ob_start();

參考

3

GD錯誤ORS,

libjpeg: recoverable error: Premature end of JPEG file

...is not a valid JPEG file

是不言自明。您正在嘗試使用的圖像沒有被底層的JPEG解析器識別爲有效。該文件很可能已損壞或被截斷。

這是圖像本身的問題,而不是您的代碼。你的代碼看起來很好。

2

看起來像你想加載的圖像不是真正的JPG(可能有人剛剛重命名或某事)。嘗試使用一些圖像處理程序(如GIMP)重新保存它。或者,如果您已將其上傳到服務器,則可能是上傳時出現了一些錯誤。另外,如果文件權重超過一個文件大小限制在服務器上,它可能會殘酷地切割。

Warning: Cannot modify header information - headers already sent by (output started at /home/rumdood/lib/photograph.php:309) in /home/rumdood/application.php on line 22 

您必須在代碼開始時發送標題。 <?php標籤之前不能有空格。

+1

我期待「頭已發送」的錯誤是抱怨事實錯誤消息被髮射並且輸出緩衝未被使用。 – Charles 2011-04-04 06:31:14