【问题标题】:suppressing php imagecreatefromjpeg errors抑制 php imagecreatefromjpeg 错误
【发布时间】:2018-08-08 17:20:09
【问题描述】:

我有一个处理上传 jpg 的脚本,无论出于何种原因,一些 jpg 似乎不符合 imagecreatefromjpeg 的任何期望。我怀疑它与全景图像有关,但还没有时间追查它。我准备跳过有缺陷的 jpg,支持 99% 的工作正常。但是,我似乎无法让我的脚本通过这些小问题之一。每次将这些有缺陷的 jpg 文件之一上传到文件池中时,我都会收到一条内联错误消息:

错误编号:8

错误描述:imagecreatefromjpeg(): gd-jpeg, libjpeg: 可恢复错误:顺序 JPEG 的 SOS 参数无效

知道这里可能发生了什么吗?我已尽我所能防止错误使此操作脱轨...然而,我们到了。

$filename = './uploads/'.$uniqIDStr.'.jpg';
move_uploaded_file($tmpfile, $filename);
$imageResource = false;
try{
    ini_set('gd.jpeg_ignore_warning', true);
    $imageResource = @imagecreatefromjpeg($filename);
    if(!$imageResource){
        $imageResource=@imagecreatefromstring(file_get_contents($filename));
    }
} catch (Exception $e) {
    echo 'Rejecting ' . $fileupload['name'] . ' because the file has some confusing properties...' . $e->getMessage(); 
    unlink($filename);
}
if($imageResource!=false){/***....***/} 

Click here for example jpg that derails everything

【问题讨论】:

  • 分享一张“不开心”图片怎么样?
  • 刚刚在底部添加了一个“坏” jpg 的链接 :)
  • 您是否设置了自定义错误处理程序?如果是这样,请在此处阅读...anvilstudios.co.za/blog/2010/04/09/…
  • @MarkSetchell 很好,是的,我有一个自定义错误处理程序,您链接的文章中的修改解决了我的问题。谢谢!
  • @MarkSetchell 你的链接失效了。

标签: php gd libjpeg php-7.1 error-suppression


【解决方案1】:

设置 PHP 忽略 jpeg 警告

ini_set('gd.jpeg_ignore_warning', 1);

就在调用 imagecreatefromjpeg() 之前的行

【讨论】:

    猜你喜欢
    • 2018-11-30
    • 2013-01-16
    • 2013-02-18
    • 2012-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多