You can write text to a canvas using the imagestring() or imagestringup()

imagestring($img, $font, $x, $y, $s, $color);

Where $font can be a font resource of a loaded font, or a built in font can be used by specifying an integer 1 - 5

Using the imagestring() function with built in fonts
<?php
    define("WIDTH", 450);
    define("HEIGHT", 100);

    $img = imagecreate(WIDTH, HEIGHT);

    $white = imagecolorallocate($img, 255,255,255);
    $black = imagecolorallocate($img, 0,0,0);

    imagerectangle($img, 0, 0, WIDTH-1, HEIGHT-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 += 15;
    }
    
    imagepng($img);
?>