When placing text on a canvas, there are a few support functions that can help you place the text properly.

imagefontwidth($font) - Returns the width of the specified user / built-in font

imagefontheight($font) - Returns the height of the specified user / built-in font

<?php
    define
("WIDTH"450);
    
define("HEIGHT"100);

    
$img imagecreate(WIDTHHEIGHT);

    
$white imagecolorallocate($img255,255,255);
    
$black imagecolorallocate($img0,0,0);

    
imagerectangle($img00WIDTH-1HEIGHT-1$black);
    
    
$start_x 10;
    
$start_y 10;
    
    for(
$font_num 1$font_num <= 5$font_num++) {
        
        
imagestring($img$font_num,
                    
$start_x$start_y,
                    
"Font #$font_num"$black);
                    
        
$start_y += imagefontheight($font_num)+3;
    }
    
    
imagepng($img);
?>