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.

<?PHP
$this
->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){
        global 
$userkey;
        
$p '?text='.urlencode($text).
             (!
is_null($font)?'&size='.$size:'').
             (!
is_null($font)?'&font='.$font:'').
             (!
is_null($color)?'&color='.$color:'').
             
'&a=';
        return 
$p.md5($userkey.$text.$size.$color.$font);
    }
?>
<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');
echo 
$img->makeImage('html');
?>

The output would be:
example+2
<img title="example 2" alt="example 2" src="http://www.codefuture.co.uk/projects/textimage/cftextimage/cache/1a6ce7e8d511fc2e4ed1beec915bfeb2.png">

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);
imagealphablending($imtrue);
imagesavealpha($imtrue);
header('Content-type: image/png');
imagepng($im,'textimage.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

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 Image IP 0.91
Image IP is a very simple but powerful PHP IP Image Generator script.This Script will...
Time Greeting
Don't just welcome your visitors any more, with this JavaScript wizard you can welcome...
MD5 Hash Generator
Message-Digest 5 is a widely-used cryptographic hash function with a 128-bit hash value.

Forum Topics

Essay writing Help
Many people struggle greatly with writing essays. From developing topics, to conducting research, to...
Problem with ban users
Hello! Sorry to my English. I add user to ban list, but he still can upload images. How fix it? Thanks.
Remote Upload
Remote Upload works not on 1.6.5 with nginx, php 5.6.30, can anywhere tell me who is the problem ?
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?