This script checks to see wether an image exists. If the image does not exist the image is created.
$text = $_GET['text'];
/// check if artist title image exists
$fp = fopen("./images/gd_text/"."$text".".png", 'r');
if ($fp)
{
// do nothing
}
else
{
$font = "EUR.TTF";
if(!isset($s)) $s=10;
$size = imagettfbbox($s,0,"$font",$text);
$dx = abs($size[2]-$size[0]);
$dy = abs($size[5]-$size[3]);
$xpad=3;
$ypad=4;
$im = imagecreate($dx+$xpad,$dy+$ypad);
$bg = ImageColorAllocate($im, 64,73,56);
$white = ImageColorAllocate($im, 218,216,203);
ImageRectangle($im,0,0,$dx+$xpad-1,$dy+$ypad-1,$bg);
ImageTTFText($im, $s, 0, (int)($xpad/2)+1, $dy+(int)($ypad/2), $black, "$font", $text);
ImageTTFText($im, $s, 0, (int)($xpad/2), $dy+(int)($ypad/2)-1, $white, "$font", $text);
ImagePng($im, "./images/gd_text/"."$text".".png");
}
How can I dispaly the image (once found or created) in the script so I can call it like this:
<img src=\"/images/gd_text/gd_title.php?text=mytext\">
Header("Content-type: image/png");
display("./images/gd_text/"."$text".".png")
😕