Intervention / image

PHP Image Processing
https://image.intervention.io
MIT License
13.84k stars 1.5k forks source link

256MB exhausted on "read" a 5MB image #1310

Closed christoferd closed 6 months ago

christoferd commented 6 months ago

Describe the bug Intervention (with GD driver) using too much memory to read a 5MB jpg file.

Code Example $manager->read($filePathTo5MBjpg)

Expected behavior Expect the system to read the file as there is 256MB allocated to PHP.

Images Not applicable. It's a normal photo taken on phone with Android OS

Environment (please complete the following information):

olivervogel commented 6 months ago

Unfortunately, memory consumption with the GD library is a recurring problem.

With the GD library, you cannot directly equate the file size with the memory consumption. GD unfortunately consumes much more; for an image with 4000x3000 pixels, RGB, 8 bits per channel, for example, you have to allocate about 50 MB just to get it into memory, even if it only takes up about 2-3 MB on the hard disk. Each manipulation requires additional memory.

In the read() function, in addition to reading the image, the EXIF data is also extracted (for the Jpeg format) and, depending on that, an alignment (rotate/flip) is performed, both of which continue to consume memory.

I recommend using Intervention/Image with Imagick if you are working with large images. It is much more memory efficient.

PS: I don't like to play the "works-on-my-machine" card, because I know it does not help, but I just did a quick test in my environment and read in the following 5.2 MB JPG image. Which worked without any problems, even with 128MB memory limit.

Environment

christoferd commented 6 months ago

Okay, thanks, will use Imagick