Laravel 4.2 抛出 NotReadableException “不支持的图像类型。GD 驱动程序只能解码 JPG、PNG、GIF 或 WebP 文件。”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52486859/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:05:09  来源:igfitidea点击:

Laravel 4.2 throws NotReadableException "Unsupported image type. GD driver is only able to decode JPG, PNG, GIF or WebP files."

laravelimagejpeggd

提问by wesol3d

After checked about 20 solutions I gave up and need help. I've got 2 JPG files. Both have proper mime, they are not too big for upload_max_filesize, names are ok, path is ok. Every solution was about one of those issues.

在检查了大约 20 个解决方案后,我放弃了并需要帮助。我有 2 个 JPG 文件。两者都有适当的 mime,它们对于upload_max_filesize 来说不是太大,名称还可以,路径也可以。每个解决方案都与这些问题之一有关。

My problem is when I run script on first image it is ok, no error, object is created:

我的问题是当我在第一张图像上运行脚本时,它没问题,没有错误,创建了对象:

$image1 = Image::make(public_path()."/uploads/goodimage.jpg");

See example:https://app.esticrm.pl/uploads/goodimage.jpg

参见示例:https : //app.esticrm.pl/uploads/goodimage.jpg

When I run it on other picture I'm getting error:

当我在其他图片上运行它时,出现错误:

$image2 = Image::make(public_path()."/uploads/badimage.jpg");

See example:https://app.esticrm.pl/uploads/badimage.jpg

参见示例:https : //app.esticrm.pl/uploads/badimage.jpg

Error message:

错误信息:

Intervention \ Image \ Exception \ NotReadableException Unsupported image type. GD driver is only able to decode JPG, PNG, GIF or WebP files.

Intervention \ Image \ Exception \ NotReadableException 不支持的图像类型。GD 驱动程序只能解码 JPG、PNG、GIF 或 WebP 文件。

Same situation on Windows and Linux. Files are opening on every graphic program and browser I've checked. Those problems has started after PHP upgrade from 5.5.x to 5.6.35. Was fine before.

Windows 和 Linux 上的情况相同。文件在我检查过的每个图形程序和浏览器上打开。这些问题是在 PHP 从 5.5.x 升级到 5.6.35 之后开始的。之前还好。

回答by wesol3d

Ok, I found solution:

好的,我找到了解决方案:

$image2 = Image::make(file_get_contents(public_path()."/uploads/badimage.jpg"));

Works also on file object from form:

也适用于表单中的文件对象:

$image2 = Image::make(file_get_contents(Input::file('upload_file'));

回答by Evan

I had the same problem and my way of solving was the next. I had to change the size that nginx allowed the user to upload in /etc/nginx.conf, like this:

我有同样的问题,我的解决方法是下一个。我必须更改 nginx 允许用户在 /etc/nginx.conf 中上传的大小,如下所示:

 http {
    client_max_body_size 100M;
 }

And I had to change also my php.ini, to increase the size of the files uploaded and the total size:

我还必须更改我的 php.ini,以增加上传文件的大小和总大小:

upload_max_filesize = 4M
post_max_size = 16M

I hope helps someone

我希望能帮助某人

回答by Kajan Thadsanamoorthy

change following variables in php.ini file

更改 php.ini 文件中的以下变量

post_max_size = 128M
upload_max_filesize = 128M
post_max_size = 128M
upload_max_filesize = 128M

print phpinfo() to find your php.ini location.

打印 phpinfo() 以找到您的 php.ini 位置。

If its cpanel its under software section->php versions-> click on "Switch To PHP Options" . Then change the value. Also change the max_execution_timeto 600

如果它的 cpanel 位于软件部分-> php 版本-> 单击“切换到 PHP 选项”。然后更改值。也更改max_execution_time600