Image: Allowed memory size of 134217728 bytes exhausted

Created on 6 Jun 2016  路  4Comments  路  Source: Intervention/image

FatalErrorException in Decoder.php line 28:
Allowed memory size of 134217728 bytes exhausted (tried to allocate 29708800 bytes)

its related to the encode especially from png to jpg, using destroy() makes no difference.

code

foreach ($photos as $one) {
            $newName = $i++ . '.jpg';

            $image = Image::make($one)
                ->resize(800, null, function ($constraint) {
                    $constraint->aspectRatio();
                    $constraint->upsize();
                })
                ->encode('jpg', 100)
                ->save("sopath/$newName"))
                ->destroy();
        }

Most helpful comment

Resizing images is a very memory consuming task. You can't assume that a 1MB image takes 1MB of memory. Resizing a 3000 x 2000 pixel image to 300 x 200 may take up to 32MB memory for example. Even if the image is under 1MB filesize.

All 4 comments

i found the issue, apparently the package doesn't work under some memory limit cuz currently i have it set to 128M ,
so i thought maybe we need to pump it up to 134M but that also doesn't solve the issue,
so i changed it again to 256M and now all is good, please note that not always that exception comes up, sometimes the server just crash HTTP ERROR 500.

so is there anyway we can debug this or get the exact amount of memory it needs to process a one 3mb image ?

http://stackoverflow.com/questions/34543732/laravel-5-2-intervention-image-500-server-error

Resizing images is a very memory consuming task. You can't assume that a 1MB image takes 1MB of memory. Resizing a 3000 x 2000 pixel image to 300 x 200 may take up to 32MB memory for example. Even if the image is under 1MB filesize.

Switch the driver to Imagick. It uses less memory.

@fahmilatib Is right, use Imagick driver. I faced the same issue on my side project (https://wizlogo.com) Intervention is using GD by default. If you need any help, feel free to contact me.

Basically you can add this to your constructor and it will do - Image::configure(array('driver' => 'imagick'));, of course you need to enable imagick extension before using it - "require": { "ext-imagick": "*", "php": "^7.1.3", "ext-gd": " *",

Was this page helpful?
0 / 5 - 0 ratings

Related issues

divdax picture divdax  路  7Comments

knif3rdev picture knif3rdev  路  6Comments

samwalshnz picture samwalshnz  路  8Comments

cherrycoding picture cherrycoding  路  3Comments

p4bloch picture p4bloch  路  6Comments