Re: Looking for a particular script
| From: | Rasmus Lerdorf | Date: | Thu, 14 Sep 2000 01:01:32 +0000 |
| Subject: | Re: Looking for a particular script | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-16703@lists.php.net to get a copy of this message | ||
> I once saw a php script that created graphics (buttons) by taking an image
> and then pasting (overlaying) text in a font over the top. This script was
> great for dynamically creating graphics for database queries and such. But
> for the life of me I cannot find it again. I kind of stumbled across it when
> I first found it, but I thought I would ask the list if they knew of the
> said script and if there was somewhere I could get it again.
>
> I believe that the script could display the text in any true type font that
> was avialable, as long as they were installed on the server.
>
> Any help would be great as I really need to create a series of images on the
> fly via a script such as this.
It's pretty trivial to do. For example, this would draw white text in the
whatever.ttf font on the button.png background:
Header("Content-type: image/png");
$font = "whatever.ttf";
$im = ImageCreateFromPNG("button.png");
$black = ImageColorAllocate($im,0,0,0);
$white = ImageColorAllocate($im,255,255,255);
ImageTTFText($im, 12, 0, 5, 14, $white, $font, $text);
ImagePNG($im);
You might want to add some logic to center the text. You are probably
referring to a phpbuilder article I wrote on this ages ago:
http://www.phpbuilder.com/columns/rasmus19990124.php3
-Rasmus