JPG' is not a valid JPEG file

AndyYang| 阅读:3132 发表时间:2014-01-09 19:51:51 php
摘要:今天测试提了一个bug过来,在上传照片的时候,遇到一个很奇怪的问题,图片上传完之后,显示一个黑图。我们调侃他说是不是看片看多了,连图片都中毒了。
今天测试提了一个bug过来,在上传照片的时候,遇到一个很奇怪的问题,图片上传完之后,显示一个黑图。我们调侃他说是不是看片看多了,连图片都中毒了。

刚开始还以为是缩略图的类有问题,后面想一下没道理啊,其他的都正常的,为什么就这个出错。然后直接访问图片显示:
图像 “http://www.trend.com/thumb.php?w=180&h=160&t=f&url=./data/uploads/2013/1213/17/52aacca80e48f.jpeg” 因其本身有错无法显示。

然后一步步调试,发现在缩图的时候报了个警告:
Warning: imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file in E:\landray\04sns\trunk\thumb.class.php on line 45
Warning: imagecreatefromjpeg(): './data/uploads/2013/1213/17/52aacca80e48f.jpeg' is not a valid JPEG file in E:\landray\04sns\trunk\thumb.class.php on line 45

搜索发现:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.
You can now allow the jpeg decoder to be more tolerant/weak:
error_reporting(E_ALL);
// 0 is the current behavior
ini_set('gd.jpeg_ignore_warning', 1);
$im = imagecreatefromjpeg($file);

原文出自:https://bugs.php.net/bug.php?id=29878

于是在代码中加入:
ini_set('gd.jpeg_ignore_warning', 1);
成功!

本文为AndyYang原创,转载请注明出处!
如果您觉得好,可以打赏作者:
如果您觉得累了,是否想看点美女养养眼:猛戳>>朋友帮
如果您觉得皮了,是否想来点神吐槽:猛戳>>iPhone查询中

已有0条评论

昵称:
邮箱:

  • 最新评论

iPhone查询中 - bbs.ipcxz.com 朋友帮 - www.pengyb.cn iPhone查询中 - bbs.ipcxz.com
反馈
微信订阅号