Easiest thing to do:
1.) Get the string, decode from URL, determine length ([man]strlen/man)
2.) Multiply that by the width of the font you're using ([man]imagefontwidth/man)
3.) Add a padding number (say 10px)
That gives you your total width!!
Now, create an image with [man]imagecreate/man.
THIS IS WHERE THE BACKGROUND COLOR IS:
Allocate the first color of the image with [man]imagecolorallocate/man
Then go from there writing your string to the image and displaying.
Something like:
<?php
$string = urldecode($_GET['lo']);
function ImageFontWidthByFilename($filename)
{
$handle = @fopen($filename,"r");
$c_wid = @fread($handle,11);
@fclose($handle);
return(ord($c_wid{8})+ord($c_wid{9})+ord($c_wid{10})+ord($c_wid{11}));
}
$font = 'arial';
$fontsize = 22;
putenv('GDFONTPATH='.realpath('.'));
$fwidth = ImageFontWidthByFilename('./arial.ttf');
$width = (strlen($string)*($fwidth+($fontsize-3)))+20; // 20 for 10px padding on each side
$im = imagecreate($width, $fontsize+10);
$black = imagecolorallocate($im, 0,0,0); // Sets BG color
$fontcolor = imagecolorallocate($im, 255, 0xCC, 0); // Sets text color
imagettftext($im, $fontsize, 0, (round(($width-strlen($string))/2)), ($fontsize+5), $fontcolor, $font, $string);
header('Content-Type: image/jpeg');
imagejpeg($im);
?>