Laravel 5.2 Intervention Image 500 Server Error
Asked Answered
A

5

10

When I upload big images (4.2 MB) Intervention Image is throwing 500 Error...

private function resizeImage($path, $imgName){
    $sizes = getimagesize($path.$imgName);
    if($sizes[0] > $sizes[1]){
        ImageManagerStatic::make($path.$imgName)->fit(920,474)->insert(public_path() . "/uploads/applications/watermark.png",'bottom-right', 30, 30)->save($path."1_".$imgName);
    }else{
        ImageManagerStatic::make($path.$imgName)->heighten(474)->insert(public_path() . "/uploads/applications/watermark.png",'bottom-right', 30, 30)->save($path."1_".$imgName);
    }
    ImageManagerStatic::make($path.$imgName)->fit(440,226)->save($path."2_".$imgName);
    File::delete($path.$imgName);
}

It works for smaller files. upload_max_filesize=10M. When I comment this function it works :/

Antisepsis answered 31/12, 2015 at 8:54 Comment(1)
is there a way to get a descriptive error message? i'm sure it throws up with more than saying 500 server error. Turn on errors and logging in php.Baba
S
19

I had the same issue and increasing upload_max_filesize were not enough. I also increased memory_limit to 256M and restarted the server. Then images were working with Intervention. [Above changes are in php.ini file]

You may want to change upload_max_filesize and memory_limit according to file capacity you are using.

Syncope answered 22/4, 2016 at 9:2 Comment(2)
I'm also getting same issue and increased all mentioned fields but still not working. Strange thing is it works for 10mb image but throwing error for 5mb image.Swart
See the server error logs and apply fixes based on them.Syncope
B
8

Today I got the same issue in Laravel 5.5 while using Intervention Package for resizing images exactly at below code:

Image::make($image_tmp)->save($image_path);

I don't have access to php.ini file in server and server will take time for update so temporarily increased memory limit in function itself in my Controller file like below:

In ImagesController.php file :-

public function addImage(Request $request){

    // Temporarily increase memory limit to 256MB
    ini_set('memory_limit','256M');

    $extension = Input::file('image')->getClientOriginalExtension();
    $fileName = rand(111,99999).'.'.$extension;
    $image_path = 'images/'.$fileName;
    $image_tmp = Input::file('image');
    Image::make($image_tmp)->resize(1182, 1506)->save($image_path);
}

Hope it will help someone in future!

Ballata answered 29/3, 2018 at 7:37 Comment(0)
T
6

I had the same problem with Laravel 5.1 and Intervention Image library. In my case the issue came from the line Image::make($file) not the upload part.

I tried change the values of:

  • upload_max_filesize from 2M to 32M
  • post_max_size from 2M to 32M

Change nothing to the error I received.

So I increase :

  • memory_limit to 256M

It solved my problem. My hypothesis is that even if my image was about 6Mo, the image library needed a lot of memory to use it.

Tyrosine answered 1/6, 2016 at 15:55 Comment(0)
G
4

edit your php.ini:

upload_max_filesize = 40M

post_max_size = 40M

Maybe your post_max_size is under 4MB. And then restart the server.

Goddord answered 31/12, 2015 at 9:29 Comment(1)
I think ImageManagerStatic has max file size 4MB. Where can I edit this limitation?Antisepsis
G
1

I tried every solution but i forgot to write into my file use Image; and this works.

Guillotine answered 19/9, 2020 at 6:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.