PDA

View Full Version : [RELEASE] Habbo Text Generator



Dentafrice
12-01-2009, 02:44 AM
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:

http://www.tehupload.com/text/index.php?text=hey

http://www.tehupload.com/text/index.php?text=hey&style=simple

http://www.tehupload.com/text/index.php?text=hey%20der&style=habbowood

http://www.tehupload.com/text/index.php?text=Habbox%20Forum&style=habboclub

http://www.tehupload.com/text/index.php?text=Caleb%20Mingle&style=trophy

http://www.tehupload.com/text/index.php?text=battle%20ball&style=battleball

Download (fonts + code): http://u.dopaul.com/text_generator.zip

Fonts List:
------------------------


Bathroom
Battleball
Bling
Chinese
Disco
Explore
Football
Habboclub
Habbowood
Iced
KEyboard
Lido
Love
Original
Recycler
Simple
Space
Tele
Trophy
Code (no fonts) - http://dentafrice.pastebin.com/m15f158ed
------------------------


<?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

Calon
12-01-2009, 02:46 AM
Hai, Mr. Mingle.

Nice release, code is excellent as usual.

*jealous*

Jin
12-01-2009, 02:55 AM
Good stuff Caleb, May see this on the Habbox site in a short while.

Dentafrice
12-01-2009, 03:04 AM
Awesome! :)

You can also make your own fonts for it.. ignore the badly positioned and ugly text.. that was my fault on photoshop.

http://www.tehupload.com/text/index.php?text=caleb&style=scrib

Cushioned
12-01-2009, 03:33 AM
How do you add your custom fonts?
I'm a bit confused as to why you can't type what font you want and then choose font style...?

Dentafrice
12-01-2009, 03:35 AM
How do you add your custom fonts?
You have to create each letter one by one and save them in a directory..

Cushioned
12-01-2009, 04:23 AM
You have to create each letter one by one and save them in a directory..

Yeah I figured that much out :P

Make it like a normal font gen where you type your font, then choose the font style and click generate, then it shows up on page.
http://www.habbotimes.net/fancenter/schriftgenerator

There are font previews and you click on them for the style you choose :D

Dentafrice
12-01-2009, 04:45 AM
I can't be bothered to do that. Someone can if they want. This is just the coding for it

Calon
12-01-2009, 04:57 AM
I can't be bothered to do that. Someone can if they want. This is just the coding for it
I could do this if more details could be specified of what needs adding.

Dentafrice
12-01-2009, 12:18 PM
I could do this if more details could be specified of what needs adding.
We'll see later today. Shouldn't be too hard.

Meti
15-01-2009, 05:12 PM
Nice of you doing this Caleb.
Looks good.

Dentafrice
15-01-2009, 06:25 PM
Thanks :)

DeejayMachoo$
15-01-2009, 11:58 PM
Nice one again caleb :) Never fail to impress.

Want to hide these adverts? Register an account for free!