While remodeling a client site not long ago, I wanted to auto-generate a text image that displayed the title or subject of the page in the pageâs header area.
I had used standard transparent gif images with drop shadows for page titles in the previous incarnation of the site; I didnât want to recreate all those title images in the new site style. I wanted something simpler and easy to configure this time around.
I had read about CSS-created drop shadows for images:
â¦but thatâs not really what I needed.
PHP image creation routines, to the rescue.
You can have a look at the completed code here:
First, this code requires both the GD library and the FreeType library compiled with your serverâs version of PHP.
Second, the code is called via an <img> tag, like:
<img src="image.php?t=The Title&f=24">
The text to be rendered into an image and the font size are passed as arguments via the $_GET[âtâ] and $_GET[âfâ] values.
Third, with a few modifications, any of the values set in the âSETUPâ area of the image.php could easily be passed to the script via $_GET through the <img> tag, allowing some flexibility in how text titles are rendered from page to page in a site.
Finally, hereâs an example of using the script, where the title âUpdating Your Accountâ is rendered as a header image for the page:
The script can render images as png, gif, or jpeg.
If you need a down-and-dirty script to generate simple text images, this might be for you!