Short answer: memory_limit=512M
Long answer:
When your image is processed, each pixel needs some memory, so the problem is not the compression, but the amount of pixels and channels.
A simple rule is width x height x 4 (rgba) = needed memory in bytes
, but that rule may break in some scenarios. I read somewhere, to use a multiplier of 5
to be on the save side. Let’s stick with 4
.
An example with your image:
6811 * 13622 * 4 = 371117768 = 354 MiB
Cockpit needed 2 MiB
already and the image processing needs 21 MiB
extra. Give it some extra space, because you never know - let’s say 128 MiB
.
So, 354 + 2 + 21 + 128 = 505 MiB
Conclusion
PHP GD is not the best option to process images. It has some troubles with transparent images (but that’s another story), it has inconsistencies with bundled and non-bundled PHP versions (even another story) and it may stop the script due to high RAM usage without any error message. But it exists, a lot of libraries use it, there is no native alternative, because not all (shared) hosts provide ImageMagick and it works in most cases.
If you really need to process very large images server side, you should consider increasing the memory_limit
even more or you should build a workaround to process them in the background or client side.
Disabling ColorThief
or switching to ImageMagick
won’t solve the problem. Every time, a new thumbnail is created, the SimpleImage
library is called, which uses the original image as base, uses GD and has the same problem: imagecreatefromjpeg()
needs a lot of RAM.