53x11.com



GDFont Renderer, 2.0

Sunday, April 17th, 2005 @ 5:08 PM - code

» Download GDFont Renderer, 2.0 (.zip 182kb)

Latest Version Released on August 15th, 2008

Licensed under BSD, Copyright © 2010

Hello, I Was Generated Dynamically

Nevermore be shackled by the appearance of jagged fonts. Release the bonds of using the same tired web typefaces over and over again. Save yourself immeasurable hours of creating individual text images for titles. The time has come to bathe in the omnipotence of dynamically generated text images. By harnessing the power of PHP and the commonly built-in GD Library, you too can become a god among men.

This super-lightweight script allows you to render any text into any TrueType font that is then displayed as an image on your web page. It includes the option to cache images to reduce server load.

This script requires PHP 4.3 or greater and the PHP GD Library installed on your server (very common library).

  1. To test if your server meets the requirements, upload the file server_test.php to any directory and run it from your browser. The script will let you know if your server is properly configured.

  2. Open font.php with a text editor to configure the default script variables.

    Setting $cache to true is recommended. If you enable caching, you must list a directory in $cache_path.

  3. The image-text that the script outputs can be controlled using any combination of the following three methods:

    • Default values (as set in font.php)
    • font_style.php values
    • $_GET values set when calling the script

    Each method overrides the one before it.

  4. There are quite a few variables you can use to make your image-text look exactly how you would like it to. The variables are all explained in the font_style.php file.

    $vadj and $hadj variables require a little further explanation. GDFont Renderer script makes a really good guess at the final outcome of what your fonts will look like and how much of them it needs to display. However, on certain fonts, it will add too much space below the last line of text - or sometimes cut-off the last letter. These two adjustment variables allow you to compensate for the graphical mix-ups. They can be negative or positive numbers (in pixels)

  5. Upload all files to your server. Please keep the verdana.tt file around, as it is the default font used when administering the script.

  6. Any fonts you plan on using must be uploaded to the $font_path as declared in font.php. This script only works with .ttf TrueType Fonts. Please note, that while most FTP clients determine this automatically, all font files need to be uploaded in Binary mode.

  7. Now, to turn any text into a rendered font, insert the following line of code in your HTML code, in-lieu of "Your Text".

    <img src="font.php?text=Your Text Here&style=title" />
    

    Obviously "Your Text Here" is replaced with your text and "Title" is replaced with the name of the appropriate style as listed in your font_style.php file.

    You can also use an inline method by including any of the variables listed in font_style.php.

    <img src="font.php?text=Hello World&font=arial&size=15&color=#666699" />
    

    Furthermore, you can use a combination of both font_style.php and inline methods. Any Inline variable called will override the font_style.php variables.

    <img src="font.php?text=Hello World&style=title&font=visitor&padding=30&alignment=right" />
    

    The only required variables in all of these methods is $text.

  8. The script includes an easy method to clear the image cache (which may be useful depending on how often you render text). All you need to do is access font.php directly without any variables. Bam, cache cleared.

    This feature can also be run as a Cron Job. The following Cron Job is a sample and will clear your cache every 2 weeks.

    0 3 14 * 0 /usr/local/bin/php public_html/font.php
    

    You will need to alter the PHP location and root location of your font.php to match your server.

If you have a working knowledge of PHP, the possibilities to dynamically generate text and styles are endless. Since you can cache any image created, this script can implemented anywhere and everywhere without bogging down your server load or download times.

The only drawback to this system is that outputted text is no longer selectable. However, if you make sure to include detailed alt tags within all your images, the text will be accessible on all browsers and can be registered by search engines.

Tidbits of this script were blatantly stolen from Stewart Rosenberger's Dynamic Text Replacement script.

Article was last edited on Tuesday, September 23rd, 2008 @ 9:24 AM

Commenting has been disabled for this article. No futher comments may be added.

Version History

2.0 (08/08/14) - Complete script rewrite. Added GIF support, vastly improved cache speed, legacy support for older font_style.php sheets, a new direct access admin dialog and fixed the glaring issue of relying on register_globals.

1.7 (05/04/17) - Added ability to align fonts and adjust padding.

1.5 (05/04/16) - Rewrote most of the script, Added image cache, cache clear, better multi-line engine, alpha support, auto-check GD Version, auto file format, HEX to RGB function, and font style sheets.

1.0 (05/04/04) - Basic text rendering functions, with a semi-retarded multiline engine.

Comments

Axel says
Saturday, May 21st, 2005 @ 6:22 PM

What are the differences between your script and Stewart Rosenberger's Dynamic Text Replacement script?

Nick says
Saturday, May 21st, 2005 @ 6:41 PM

Differences between GDFont Renderer and Stewart Rosenberger's Dynamic Text Replacement script?

Ability to make multi-line text (with definable line-height), a "stylesheet" for multiple styles, inline styles defined via URL variables, center and right justified text, alias (unsmoothed fonts) output, and padding.

Johnathan Powell says
Thursday, July 21st, 2005 @ 8:30 PM

Hi, I love the script. I was wondering if you would consider making it so that the script can be called without breaking validation. I think the main culprit is using the & in the image tags.

If there is already a way to avoid this, I would love to know.

Great work!

-Johnathan

Nick says
Saturday, July 23rd, 2005 @ 8:10 AM

To validate an ampersand, just replace every & in your HTML and URLs with &amp;amp;

Alex says
Wednesday, July 27th, 2005 @ 9:19 AM

Please add support for "register_globals off" which is the standard option for the latest PHP installations.

Nick says
Wednesday, July 27th, 2005 @ 12:40 PM

I am really busy right now with other projects, for the time being add:

foreach($_GET as $key => $value)
    $$key = $value;

Just after <?php in the file font.php.

Daniel BOlivar says
Saturday, August 13th, 2005 @ 3:44 PM

Hi..

I'd like to incorporate this into products in my Zen Cart (OsCommerce) as a text options previewer.

Would you be willing to do this? What do you charge for work? Or could you possibly point me in the direction of a programmer that would be capable of doing it?

thanks for posting this... I only wish I were a programmer!

CHEERS!

Gijs says
Wednesday, September 7th, 2005 @ 3:31 AM

Thanks for sharing this script! I am looking forward to seeing your weblog script.

Leon Bogaert says
Monday, October 24th, 2005 @ 7:06 AM

In the near future will there be a version where you can specify a background-image?

Nice says
Friday, October 28th, 2005 @ 7:01 AM

nice script! it would be great if the script can show shadow color for the text. so it will be show 3D :) any suggestion pls?

Alfonso says
Monday, September 1st, 2008 @ 11:30 AM

I love your font library, I use it for a long time. When I saw there was a new version I was excited.

Only one thing, the only one that worries me. I would like to use fixed line heights: "Summer" and "summer" or "moon" and "loom" doesn't lay over the same line, this make it difficult to standarize titles.

Am I missing something? If not, I hope this is useful to you.