Hi.
I've got this simple snippet:
// Set the content-type
header("Content-type: image/png");
/* image dimension */
$width= 400;
$height= 300;
$fontSize= 15;
$paddingBottom= 5;
$paddingRight= 5;
$text = 'Whisher';
$smallW= $fontSize+$paddingRight;
$smallH= (strlen($text)*$fontSize);
/* Main */
$im = imagecreatetruecolor($width, $height);
$red = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, $width, $height, $red);
// Create small rectangle
$grey= imagecolorallocatealpha($im, 136, 136,136, 100);
imagefilledrectangle($im, $width, $height, $width-$smallW, $height-$smallH, $grey);
// Replace path by your own font path
$font = 'fonts/monofont.ttf';
// Add the text
$dark = imagecolorallocate($im, 136, 136,136);
imagettftext($im, $fontSize, 90,$width-$paddingRight, $height-$paddingBottom, $dark, $font, $text);
imagepng($im);
imagedestroy($im);
?>
What I'm not able to work out is set dynamically
the small rectangle dimension (the background of the text).
$smallW= $fontSize+$paddingRight; (fit quite well)
$smallH= (strlen($text)*$fontSize); (this is too great)
Could you help me, please ?
Bye.