A friend of mine was asking how to do this earlier today.. so I thought I would give it a try.
No, this isn't one of those that just display the images lined up side by side.. this actually generates the image.
The image is also transparent. Here is an example:
Download (fonts + code): http://u.dopaul.com/text_generator.zip
Fonts List:
------------------------
Code (no fonts) - http://dentafrice.pastebin.com/m15f158edBathroom
Battleball
Bling
Chinese
Disco
Explore
Football
Habboclub
Habbowood
Iced
KEyboard
Lido
Love
Original
Recycler
Simple
Space
Tele
Trophy
------------------------
PHP Code:<?php
##########################################################################
/**
* Text Generation Script
* Author: Caleb Mingle
* Website: http://dentafrice.com
*
* I know this code isn't the best.. there are plenty of better ways to do it probably.. but this was just a
* few minutes of work to get this going, I know people use it.
*/
##########################################################################
/**
* Settings
*/
$default_style = 'chinese'; // this is the default font to use, if $style is not set.
$space_px = 8; // this is how many pixels we want to use for a space character.
$letter_space = 2; // this is the space we want between each letter. NOT A SPACE CHARACTER.
/**
* Data
*/
$text = $_GET["text"]; // get text
$text = ($text == '') ? 'no text' : $text; // if text is blank, show 'no text' in the image.
$style = $_GET["style"]; // get style.
$style = ($style == '') ? $default_style : $style; // if style is blank, use default style.
/**
* Text Handling
*/
$style = ucfirst($style); // turns the style's first letter uppercase for the folder.
$length = strlen($text); // counts the length of the text string.
$lower = strtolower($text); // puts the string to all lower, array.
/**
* Image Calculations
*/
$height = 0; // starts image height as 0
$width = 0; // stars image width as 0
$data_a = array();
for ($i = 0; $i < $length; $i++) {
if ($lower[$i] == ' ') {
$width = $width + 8; // if the letter is a space, add 8px to the width.
$data_a[$i]['letter'] = $lower[$i]; // letter = space.
} else {
$filename = $style . '/' . $lower[$i] . '.gif'; // sets the filename in the style folder..
$data = @getimagesize($filename); // gets the image size: width + height of the image.
$width = $width + $data[0] + $letter_space; // sets the width of the image as the original plus the new with of the letter, as well as pixels for spacing.
if ($height < $data[1]) {
$height = $data[1]; // if the current height is less then this letter's height, replace the height with this one.
}
$data_a[$i]['letter'] = $lower[$i]; // sets this as the letter.
$data_a[$i]['image'] = @imagecreatefromgif($filename); // sets this as the actual image of the letter.
$data_a[$i]['data'] = $data; // sets this as the width and height of the image, data.
}
}
/**
* Image Creation
*/
$image = @imagecreatetruecolor($width, $height); // creates the image based on the width + height we determined.
/**
* Transparency
*/
@imagesavealpha($image, true); // turns image alpha, transparent.
$trans_colour = @imagecolorallocatealpha($image, 0, 0, 0, 127); // transparent color.
@imagefill($image, 0, 0, $trans_colour); // fills the image with this color.
/**
* Letter Placement
*/
$x = 0; // sets the starting x as 0. top left corner.
$w = 0; // sets the starting y as 0. top left corner.
foreach ($data_a as $letter) {
if ($letter['letter'] == ' ') {
$x = $x + $space_px; // if the letter is a space, add the correct amount of pixels.
} else {
@imagecopy($image, $letter['image'], $x, 0, 0, 0, $letter['data'][0], $letter['data'][1]); // copies the letter to the image we created earlier, in the spot that is indicated by $x, and $y.
$x = $x + $letter['data'][0] + $letter_space; // ads to the placement x and y, width of the letter and the spacing for the letters.
}
}
/**
* Display Image
*/
header('Content-type: image/png'); // sets the header as a PNG image.
@imagepng($image); // displays the image.
@imagedestroy($image); // destroys the image.
?>
Hope you enjoy!
Caleb





Reply With Quote






