image: Cannot process image larger than 2 MB

I’m not encounter the problem when uploading, this problem happen when i process the file on the server, i also update the php.ini file on the memory and max upload file size, but not helping,

my php.ini setting:

memory_limit=256M
upload_max_filesize=32M

here is my code:

 // open an image file
$img = Image::make('msg-1-fc-40.jpg');
// finally we save the image as a new file
$img->save('test.jpg');
 //

The image is larger then 2 MB, when i do this, it return me

This page isn’t working

shamirac.dev is currently unable to handle this request.
HTTP ERROR 500

can i know what happen?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 2
  • Comments: 17

Most upvoted comments

512M for handling a 2M image ? I wouldn’ call that solved :p

I could sove this issue. It was solved modifying some configurations in php.ini file.

See bellow: upload_max_filesize = 50M memory_limit = 512M max_input_time = -1 max_execution_time = 0

Image operations tend to be quite memory exhausting because image handling libraries usually ‘unpack’ all the pixels to memory.

A JPEG file of 3MB can thus easily grow to 60MB in memory and that’s when you’ve probably hit the memory limit allocated for PHP.

As far I remember, XAMP only allocates 128 MB RAM for PHP.

Check your php.ini and increase the memory limit, e.g.: memory_limit = 512MB

Then restart the server.

But this is not a good approach, the best approach is to compress and resize any image before saving it to the server.

512 M memory limit doesn’t solve the problem, i increase it to 1000, then only work fine, but, this sound crazy when the project is on share hosting

I’ve also been struggling w/ OOM errors on my 128Mb nginx server (Docker’ized). From my debugging; I see the memory usage spike from 15Mb right up to 135Mb w/ one single image resize. The spike happens right after the line that calls the GD PHP library’s imagecreatefromstring() method which is apparently notorious for memory usage.

$resource = @imagecreatefromstring($binary);