今天测试提了一个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);
成功!
原创文章,作者:kepupublish,如若转载,请注明出处:https://blog.ytso.com/98460.html