Estimating the required memory for working with libGD

Before trying to resize the image in PHP using libGD, I would like to check if there is enough memory to perform the operation, because "out of memory" completely kills the PHP process and cannot be caught.

My idea was that I would need 4 bytes 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 have shown that this is much more memory than the library is apparently used. Can anyone suggest a better method?

+2
source share
2 answers

You should check out this comment as well as this one .

+2

, GD, imagecopyresampled, , , .

: PHP script , http:

$file = urlencode("/path/to/file");
$result = file_get_contents("http://example.com/dir/canary.php?file=$file&width=1000&height=2000"); 

( file, )

script " ", , .

, , . .

+1

Source: https://habr.com/ru/post/1761451/


All Articles