dongyiluan1718
2012-07-04 06:28
浏览 181
已采纳

为什么在php中使用imagecreatefromjpeg()函数时会收到“Corrupt JPEG data”消息?

I am using the imagecreatefromjpeg() function to upload images via an upload form:

$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);

Most photos upload fine but some display this error:

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

It seems to occur with some, but not all, '.jpeg' files. I have not seen the problem occur with '.jpg' files, but I cannot be certain that the problem is exclusive to '.jpeg' files. I did notice that if I change the extension on the problem file from '.jpeg' to '.jpg', it works just fine.

Why do I get "Corrupt JPEG data" message when using imagecreatefromjpeg() function in php?

图片转代码服务由CSDN问答提供 功能建议

我使用imagecreatefromjpeg()函数通过上传表格上传图片:

  $ 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); 
   
  
 

大多数照片上传都很好,但有些会显示此错误:

警告:imagecreatefromjpeg()[function.imagecreatefromjpeg]: gd-jpeg,libjpeg: 可恢复的错误:损坏的JPEG数据:在标记0xed之前756个无关的 字节

似乎与某些(但不是全部)“.jpeg”文件一起出现。 我没有看到'.jpg'文件出现问题,但我无法确定该问题是'.jpeg'文件所独有的。 我注意到如果我将问题文件的扩展名从'.jpeg'更改为'.jpg',它就可以正常工作。

为什么我会收到“Corrupt JPEG data”消息 在php中使用imagecreatefromjpeg()函数时?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • douqian2334 2013-04-04 04:32
    已采纳

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

    Are you just renamed it, or resaved in graphical program?

    Anyway it seems that your file is broken. Look at 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.

    打赏 评论
  • dongzhuo2371 2013-10-13 15:26

    this can be solved with: ini_set ('gd.jpeg_ignore_warning', 1);

    打赏 评论
  • douyin2962 2017-05-15 15:03

    Try adding @imagecreatefromjpeg($img) instead of imagecreatefromjpeg($img).

    Here @ is the error suppressor.

    打赏 评论

相关推荐 更多相似问题