I have a script that creates an image whose height depends on the depth of a recursive tree. Precalculating the height of the image would be a pain, because I would need to run a recursive function twice. Thus, I wonder if it is possible to resize the image from inside my only recursive function. Long story short, I need to resize an image resource, is it possible? For instance, how can I make the following code work? Thanks!
//Create the image
$image = imagecreatetruecolor(800, 100);
//Change the image height from 100 to 1000 pixels
imagecopyresized($image, $image, 0, 0, 0, 0, 800, 1000, 800, 100);
//Set the header
header('Content-Type: image/png');
//Output the image
imagepng($image);
//Destroy the image
imagedestroy($image);
Your code is almost perfect, except you aren’t giving it the source image to work with. You need
$source = imagecreatefrompng("someimage.png");, and then in yourimagecopyresizeset the source image argument to$source.