估计libGD操作所需的内存 [英] Estimate required memory for libGD operation

查看:108
本文介绍了估计libGD操作所需的内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试使用libGD在PHP中调整图像大小之前,我想检查是否有足够的内存可用于执行操作,因为内存不足完全杀死了PHP进程并且无法捕获。

Before attempting to resize an image in PHP using libGD, I'd like to check if there's enough memory available to do the operation, because an "out of memory" completely kills the PHP process and can't be catched.

我的想法是,我需要原始和新图像中每个像素(RGBA)的4字节内存:

My idea was that I'd need 4 byte of memory for each pixel (RGBA) in the original and in the new image:

// check available memory
if(!is_mem_available(($from_w * $from_h * 4) + ($to_w * $to_h * 4))){
     return false;
}

测试表明,这个内存远远超过了库真正使用的内存。任何人都可以提出更好的方法吗?

Tests showed that this much more memory than the library really seem to use. Can anyone suggest a better method?

推荐答案

你应该检查此评论,并也是这一个

这篇关于估计libGD操作所需的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆