CF TextImage Class

CF TextImage Class is a small but useful PHP script that can generates a image from a string of text using a True Type Font (ttf). This script has some simple uses such as a replacement for JavaScript cufon library when JavaScript is not available, a replacement for Flash based text or displaying a email address that cannot be programmatically found. This can help to reduce the possibility of your email address being picked up by web crawlers and used for junk mail.

How To Use This Text to Image Class?

There are many ways you can use this class,
  • Dynamic Image Generation
  • include class - Image HTML Code Generation
  • include class - PHP Image Resource
Before we set it to work, though, you will need to customize some of the default settings. You can find the default settings in the construct function of the class, there are 4 you will most likey edit for your specific purpose.

->set['fontName'] = 'ChampagneAndLimousines'// preferred TTF font
$this->set['fontSize'] = 30// preferred font size
$this->set['fontColor'] = 6// preferred font color
$this->set['userKey'] = md5('cftextimage'); // md5 sign of parameters

The 3 font default setting can be overridden dynamically when making the image, All other default settings and userKey can not be updated dynamically.
  • fontName: this must be set to the True Type (TTF) font name with out the extension (.ttf).
  • fontSize: the size of the font in points.
  • fontColor: is a hexadecimal color codes that indicate the color of the text.

The user Key is used like a password, the script uses a MD5-based authorization to avoid image generation by unauthorized users.
  • userKey This holds your userKey this help.

Where can you use it?

The first and easiest way to use this script is to call the class dynamically. Dynamic Image Generation is when the rating of a images is done on the fly. This Text to Image script will deliver a dynamic PNG image to the browser whenever it’s asked to.

To generate image with the text 'Hello World' on it, using the font LaurenScript.ttf with a size of 25px and the color #3aa3ff, you would call it like: <img alt="Hello World" title="Hello World" src="./cftextimage/cftextimage.class.php?text=Hello+World&amp;size=25&amp;font=LaurenScript&amp;color=3aa3ff&amp;a=8a3b93b3fc699ab34644e5e376a8df5a" />
Hello World Note parameter 'a=6c39e9099f6dfebf2f88172cf204e69a'. '6c39e9099f6dfebf2f88172cf204e69a' is a result of md5(userkey.'Hello World253aa3ffLaurenScript'): concatenation of secret key, text, font size, font color and font name.
You could use a helper function to set script arguments, like 'imgParams' below: <?php
// your user key
$userkey md5('cftextimage');

// returns parameters
function imgParams($text$size=null$font=null,$color=null){
$p '?text='.urlencode($text).
<img src="./cftextimage/cftextimage.class.php<?php echo imgParams('Hello World'25'LaurenScript','3aa3ff');?>" title="Hello World" alt="Hello World">

include class - Image HTML Code Generation

The second way to use this script, is by including the class in to your file. Using it this way you do not need to send the user key to the script and the script will out put the image HTML tag for you. <?PHP
include './cftextimage/cftextimage.class.php';
$img = new imageText();
$img->imageSettings('example 2'25,null,'3aa3ff');

The output would be:
<img title="example 2" alt="example 2" src="">

include class - PHP Image Resource

The last way to us this class is by having it output a PHP image Resource, so you can use the image with other php image script with out having to reopen the image from disk.
The example below shows you how you can use this to rotate the image: <?PHP
include './cftextimage/cftextimage.class.php';
$img = new imageText();
$img->imageSettings('example 3'25,'ChampagneAndLimousines','3aa3ff');
$im $img->makeImage('resource');

$im imagerotate($im$degrees0);
header('Content-type: image/png');

The output would be:
example 3 Rotate 180

System Requirements

  • Apache Web server (recommended) or IIS
  • PHP version 4.3 or greater
  • PHP extension GDLib


Download : CF TextImage Class
If you find any bugs or if you need any help please feel free to post a comment on the forum and I will answer you as soon as possible.

Other Tools

CF Users Online 0.9
The Users On-line PHP script is a very simple script what allows you to display how many...
Color Converter
This free on-line tool has been designed to enable you to quickly and easily convert in...
Redirect Page
Here's a simple way to make a redirect page to move your visitors to a another page.

Forum Topics

How I can change format and size of file uplaod
hi how i can change format of file uploaded ? and how i can change maximum size of file uploaded ? which on of...
Resposnive Theme
Is there any repsonsive or more mobile friendly theme I could use?
the Max size allowed
Sorry, the image size is to big,3300x3300 is the Max size allowed. How to increase this limit? Thnaks!
FOR ENGLISH Hello, sorry to my English. I use "Google translate". Please, help. When I go...
Help needed: To add adult image warning
I see that your script is very good and functioning very well. I would like to know wether it is possible to...