【问题标题】:GD (PHP) failing with bad JPEG image resize (Laravel Intervention\Image), no error in error.logGD (PHP) 因 JPEG 图像大小调整错误 (Laravel Intervention\Image) 而失败,error.log 中没有错误
【发布时间】:2016-09-22 02:58:04
【问题描述】:

我在 Windows 和 Ubuntu 开发盒上运行 Apache/PHP 5.6。将 Laravel 5.1 和干预/图像与 GD 驱动程序一起使用,我正在尝试调整一些相当大的图像(15-25MB)的大小,问题是调整大小失败并出现错误Unable to read image from file (/tmp/phpxxxxxx),但仅限于大图像。 5-10MB 范围内的任何内容都可以调整大小...

我假设它与内存不足的进程有关(因为较小的文件没有问题),但问题是我实际上并没有在 error.log 中收到任何错误消息...

我已将 php.ini 中的 memory_limit 增加到 2000M 进行测试,但调整大小仍然失败。

控制器中调整图像大小的代码是...

$img = Img::make($file->getRealPath());

通过 Laravel 报错的详细信息如下...

NotReadableException in Decoder.php line 46:
Unable to read image from file (C:\Apache24\htdocs\tmp\php361F.tmp).
in Decoder.php line 46
at Decoder->initFromPath('C:\Apache24\htdocs\tmp\php361F.tmp') in AbstractDecoder.php line 293
at AbstractDecoder->init('C:\Apache24\htdocs\tmp\php361F.tmp') in AbstractDriver.php line 64
at AbstractDriver->init('C:\Apache24\htdocs\tmp\php361F.tmp') in ImageManager.php line 50
at ImageManager->make('C:\Apache24\htdocs\tmp\php361F.tmp') in Facade.php line 216
at Facade::__callStatic('make', array('C:\Apache24\htdocs\tmp\php361F.tmp')) in SubmitPhotoController.php line 97
at Image::make('C:\Apache24\htdocs\tmp\php361F.tmp') in SubmitPhotoController.php line 97
at SubmitPhotoController->store()

我将如何进行进一步的故障排除以找出失败的原因?

注意事项:

  1. 我减少了memory_limit 只是为了确保在调整大小时低值会显示错误并且确实如此,所以我认为这不是 PHP 内存问题。
  2. 我确实看到文件显示在 C:\Apache24\htdocs\tmp 中,然后很快就消失了。

编辑:

upload_max_filesize = 2000M
post_max_size = 2000M

编辑 2: 经过一些测试,失败的图像是我手机上的全景功能创建的图像。即使是更小的文件大小的图像也会失败。

【问题讨论】:

  • 最好在 linux 服务器上使用你的代码,我已经看到很多使用 windows LAMP 的 strage 错误。对于大图像和视频处理,我使用 ffmpeg 来完成这部分。
  • @DionisL 在带有 PHP7 的 Ubuntu 16.04 上出现完全相同的错误。只需将C:\Apache24\htdocs 替换为/tmp/phpxxxxx
  • 会不会没时间了?检查 php.ini 中的max_execution_time
  • @DionisL 我很欣赏这个建议,但在转移到不同的东西之前尝试调试这个错误(最终可能最终成为 imagemagick)
  • @dangel 如果你真的想调试它,在你的服务器上保存一个大图像并尝试调整它的大小,这样你就消除了所有的 http 请求内容,如果它有效,那么你的有问题表单/请求,如果没有,那么您的核心 php/gd/server 设置有问题

标签: php laravel gd intervention


【解决方案1】:

需要告知 GD 忽略来自错误 JPEG 的警告,因为显然 GD 对错误或损坏的 JPEG 不太容忍。这些失败的图像实际上是使用内置全景工具在我的手机上创建的。大图在线下载或通过photoshop打开\保存(修复),我开始测试后其实还好。

ini_set("gd.jpeg_ignore_warning", 1);

https://stackoverflow.com/a/3901885/895810https://bugs.php.net/bug.php?id=39918

问题源于 Intervention\Image\Gd\Decoder.php 的以下几行

....
$info = @getimagesize($path);
...

// define core
        switch ($info[2]) {
            case IMAGETYPE_PNG:
                $core = @imagecreatefrompng($path);
                break;

            case IMAGETYPE_JPEG:
                $core = @imagecreatefromjpeg($path); //<--------here
                dd($core);
                break;

我可以想象完全忽略警告会遇到其他问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-11
    • 1970-01-01
    • 2012-08-12
    相关资源
    最近更新 更多