How can I resize an image resource in PHP?
===

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);