
See the title? The following recipe lets you have headings, titles or single-line text in any font you wish.
Example usage:
Download this file, extract it, and put it in the same directory as your php pages. Include it at the top of any of your .php files.
<?php include 'make_text_image.php' ?>
Then, at locations in the HTML where text images are needed, insert the php code, similar to that shown below:
<?php $params = array( 'color' => '#C00', 'fontpath' => 'fonts/Eurostib.TTF', 'size' => 100, 'text' => 'www.StokedAndGnarly.com', 'imagepath' => 'images/text/greeting', 'format' => 'png', ); echo make_text_image($params); ?>Returns something like:
<img src="images/text/greeting.png" border="0" width="488" height="100">
Requires PHP with the Imagick extension installed on your web server.
IMPORTANT: If you generate an image with this script and then decide to change some of the parameters, you must remember to delete the previously generated image from you images folder.
Explanation of Parameters
'color': The fill color of the text
'fontpath': the path to the font to be used to draw the text. This is relative to the site root. It is important for the font name to be an exact match to the font on the server. A copy of the font file must be uploaded to this directory for the function to work.
'size': The font size in pixels
'text': The text to be drawn into the image
'imagepath': file path and name that the new image will be stored as. Does not include the file type extension
'format': the filetype extension, such as 'gif', 'jpg' or 'png'. No period is to precede the extension