ajithlal's avatar

intervention image not resizing image greater than 15mb

Hi All,

I'm using Intervention\Image\Facades\Image to resize image. It works fine when uploading images upto 12Mb. but it is returning 500 while uploading image greater than 20Mb.

Here is my php.ini settings

max_execution_time = 1000 max_input_time = 1000 memory_limit = 1000M post_max_size = 1000M upload_max_filesize = 1000M

0 likes
10 replies
deansatch's avatar

have you checked phpinfo() to see if your settings are being recognised? Reloaded server etc..? Oh...and you do have enough ram too?

ajithlal's avatar

@deansatch when I comment the save function using Intervention, it works fine. when using the intervention it is returning 500.

Nash's avatar

Is it the correct php.ini file? Try setting the limit in your code before the Intervention function:

ini_set('memory_limit', '1000M');
deansatch's avatar

Post your code - maybe you are performing so many transformations even 1000MB isn't enough memory.

Also try freeing up memory immediately after save

$img->save('image.jpg'); $img->destroy();

ajithlal's avatar

@DEANSATCH - this is the code that i'm using for image save

$thumbFilename = "img-" . md5(rand(9999, 999999999)) . '.' . $file->getClientOriginalExtension();
                $file->storeAs('storage/uploads', $thumbFilename);

                $destinationPath = public_path('storage/uploads/');

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

                $img->resize(500, 500, function ($c) {
                    $c->aspectRatio();
                    // $c->upsize();
                })->save($destinationPath . 'thumb-' . $thumbFilename, 100);
deansatch's avatar

@AJITHLAL - did you try adding $img->destroy(); to see if that helps?

Other than that you may have to look at the error logs to see what the reason for the 500 is

deansatch's avatar

Because it is a 500 error it will not be the laravel log file, it will be your server log file

ajithlal's avatar
ajithlal
OP
Best Answer
Level 18

I've combined both of your( @nash , @deansatch ) suggestion and rewrite my code like below and it works perfect.

$orgFilename = "img-".md5(rand(9999,999999999)).'.'.$request->original_image->getClientOriginalExtension();
            $request->original_image->storePubliclyAs('uploads',$orgFilename);
            
            $destinationPath = public_path('storage/uploads/');
        ini_set('memory_limit', '1000M');
            $img = Image::make($img->getRealPath());
            $img->resize('500', '500')
            ->save($destinationPath.'thumbnail-'.$orgFilename)->destroy();

Thank you @nash and @deansatch for your help.

Please or to participate in this conversation.