Faccio riferimento al Manuale

Nel codice:
Codice PHP:
<?php
// Set the content-type
header('Content-Type: image/png');

// Create the image
$im imagecreatetruecolor(40030);

// Create some colors
$white imagecolorallocate($im255255255);
$grey imagecolorallocate($im128128128);
$black imagecolorallocate($im000);
imagefilledrectangle($im0039929$white);

// The text to draw
$text 'Testing...';
// Replace path by your own font path
$font 'arial.ttf';

// Add some shadow to the text
imagettftext($im2001121$grey$font$text);

// Add the text
imagettftext($im2001020$black$font$text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
Volevo l'immagine si adattasse a seconda della dimensione del testo.
Faccio un esempio
Se scrivo M in un corpo 25 usando come font l'arial allora l'immagine che otterò dovrà essere circa imagecreatetruecolor(30, 30); e la posizione (circa) imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
mentre se scrivo MM imagecreatetruecolor(62, 30); e la posizione e (circa) imagettftext($im, 20, 0, 10, 20, $black, $font, $text); mentre con un corpo 90 e un Arial Black, scrivendo M vorrei come risultato (circa)
imagecreatetruecolor(150, 150); e imagettftext($im, 90, 0, 12, 120, $black, $font, $text);