GD(PHP)失败,错误的JPEG图像调整大小(Laravel Intervention \ Image),error.log中没有错误

时间:2016-09-22 02:58:05

标签: php laravel gd intervention

我在Windows和Ubuntu开发框上运行Apache / PHP 5.6。使用Laravel 5.1和Intervention / Image与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中,然后迅速离开。
  3. 编辑:

    upload_max_filesize = 2000M
    post_max_size = 2000M
    

    编辑2: 在进行一些测试之后,失败的图像是我手机上的全景功能创建的图像。更小的文件大小的图像最终失败了。

1 个答案:

答案 0 :(得分: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;

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