I am using imagecreatetruecolor() to create PNG images in PHP. I often need to increase my memory_limit via an ini_set() based on the size (dimensions in pixels) of the image.
So far it has been trial / error on how much memory should be allocated based on the maximum values I am expecting to receive, but I know these values can possibly come in higher as well.
Everything within the image is being drawn using:
imagefill();
imagecolorallocate();
imagerectangle();
imagefilledrectangle();
imagettftext();
And the final output is through:
imagepng();
imagedestroy();
Currently I have it set to 512MB and it is handling most of the maximum sizes I am expecting (3178 x 2878), but I am trying to also not over-allocate memory if I am drawing something very small.
Is there a method I can use to take my image dimensions in pixels and calculate the required memory that should be allocated? Obviously I'll need to add a little extra for the overhead of processing, but I need to figure out how much memory the actual image creation uses.
Thanks!