2
votes

I know there are tons of questions regarding this problem. But I still couldn't understand the cause. The error shows when I add resize function.

Image::make($logo)->resize(200*200)->save(public_path('Uploads/logo/' . $fileName));

Otherwise it works fine. Why would a function tries to consume that amount of memory?

3
Probably it's not just that single function, but the aggregated memory consumption of your script is to high. That call was just the first to go beyond the limit. Maybe try looking through your code to find other high memory sections. - Sirko
@Sirko thanks for that knowledge.. :) - Azima

3 Answers

5
votes

When you do ->resize(200*200) you are not resizing the image to 200 pixels by 200 pixels, you are passing the width (first parameter of the resize() function) as 200 times 200, which is 40,000, hence the memory problem.

You need to do:

Image::make($logo)->resize(200, 200)->save(public_path('Uploads/logo/' . $fileName));
0
votes

Resizing can use a lot of memory. Maybe in this case the original image is big. You can try to flatten it first to a JPG and then resize it.

To increase the memory limit you can add this on top of the PHP script:

ini_set('memory_limit', '2G');
0
votes

Increase the amount of variable memory_limit = 128M in php.ini to your applications demand. It might be 256M/512M/1048M.....