Here is an example how to draw text on png image:
$img = imagecreatefrompng($image_path); //$image_path -> on which text to be drawn
@imagealphablending($img, true);
@imagesavealpha($img, true);
$textColor = imagecolorallocate($img, 100, 100, 98);
$font = '../fonts/Arial.ttf';
imagettftext($img, 18, 0, 140, 285,$textColor,$font, $name); // $name -> dynamic text to be drawn on image
$path = "path where you want to save created image";
$image = imagejpeg($img, $path);
imagedestroy($img);
done..