I want to put some restrictions to the images uploaded by the users, so the script that process them never runs out of memory.
The images that take more memory, are the ones with higher resolution. They don't need to have a big size in bytes. For example, a 46kb image, with 4000x2500 resolution, and some transparencies (PNG), took around 90mb to resize it.
Is there a way to precalculate the memory needed accurately?
Any ideas?
Data Size is its uncompressed size in bytes when the file is opened into computer memory. If the usual 24-bit image, that data size will be 3 bytes per pixel. If 24 megapixels, then 72 million pixels, which due to the 1024 thing, will be about 68.7 MB.
Converting into Mega bytes = 1024 / 1024 = 1 Mb. Thats how an image size is calculated and it is stored.
Generally, the rule of thumb is, width x height x 4 (rgba) for both the source and destination images, and don't forget about the amount of memory the script itself has already consumed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With