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

为什么在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?

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境