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

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

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog