如何计算处理图像所需的内存? [英] 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.
占用更多内存的图像,是具有更高分辨率的那些。它们不需要具有大字节的大小。例如,分辨率为4000x2500的46kb图像和一些透明胶片(PNG)需要大约90mb来调整大小。
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?
任何想法?
推荐答案
一般来说,经验法则是,源x和目标图像的宽度x高度x 4(rgba),并且不要忘记脚本本身已经消耗的内存量。
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.
这篇关于如何计算处理图像所需的内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!