2012-07-04 21 views
1

我使用imagecreatefromjpeg()函數通過上傳表單上傳圖片:爲什麼在php中使用imagecreatefromjpeg()函數時會出現「損壞的JPEG數據」消息?

$folder = '../images/'; 
$image = imagecreatefromjpeg($_FILES['image']['tmp_name']); 
$new = imagecreatetruecolor(300, 300); 
imagecopyresampled($new, $image, 0, 0, 0, 0, 300, 300, 150, 150); 
imagejpeg($new, $folder, 100); 

大多數照片上傳罰款,但一些顯示此錯誤:

Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg, libjpeg: recoverable error: Corrupt JPEG data: 756 extraneous bytes before marker 0xed

這似乎與一些發生,但不是全部,'.jpeg'文件。我還沒有看到'.jpg'文件出現問題,但我無法確定問題是'.jpeg'文件的專有問題。我注意到,如果我將問題文件的擴展名從'.jpeg'更改爲'.jpg',它就可以正常工作。

爲什麼在php中使用imagecreatefromjpeg()函數時會出現「損壞的JPEG數據」消息?

+0

在文本編輯器中打開損壞的jpeg文件,看看它包含的是什麼錯誤信息 –

+0

當我打開損壞的文件時,它是一個包含許多加密字母的文檔,如「」#ôZô÷ôÚô˝Ù»ıVV/ß »*óCàP¶UÌ°E,萊城!í'Ú+'c」 – zeckdude

回答

5

I did notice that if I change the extension on the problem file from '.jpeg' to '.jpg', it works just fine.

你剛剛重新命名它,或重新保存在圖形程序中?

無論如何,它似乎是你的文件壞了。看看Bug #39918 imagecreatefromjpeg doesn't work

GD does provide a mechanism to be more tolerant with broken jpeg images.

Using error_reporting(E_ALL); while developing would have told you what's going on. GD did report some errors in the jpeg codec. Some of the jpeg errors are recoverable, like those in this image.

You can change the behaviors of the jpeg codec using gd.jpeg_ignore_warning:

ini_set("gd.jpeg_ignore_warning", 1);

$im = imagecreatefromjpeg("test.jpeg");

$im contains now your image.

0

這可以用來解決: 函數ini_set( 'gd.jpeg_ignore_warning',1);

0

嘗試添加@imagecreatefromjpeg($img)而不是imagecreatefromjpeg($img)

這裏@是錯誤抑制器。

相關問題