Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate the memory needed for processing an image?

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?

like image 877
HappyDeveloper Avatar asked Mar 09 '11 23:03

HappyDeveloper


People also ask

How much memory is required to store an image?

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.

What is the storage requirement for a 1024 * 1024 binary image?

Converting into Mega bytes = 1024 / 1024 = 1 Mb. Thats how an image size is calculated and it is stored.


1 Answers

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.

like image 82
steveo225 Avatar answered Oct 12 '22 22:10

steveo225