Estimate required memory for libGD operation

 

Questions


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.

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?

 

 

————————————————-

Answer

You should check this comment out, and also this one.

gdlib,image-processing,memory,php

Facebook Comments

Post a comment