Decoma
20-04-2009, 01:12 AM
I've created a simple volter text font generator. This would be good to use in several projects.
The only issue is that I can't completely get anti-aliasing disabled for really small fonts, but it's only 2 or 3 pixels that aren't noticeable unless you zoomed in and closely examined the piece.
Here are a few examples:
http://habbcrazy.net/djpanel/text.php?t=HabbCrazy.NET&s=20&w=3
http://habbcrazy.net/djpanel/text.php?t=HabbCrazy.NET&s=15&w=3
http://habbcrazy.net/djpanel/text.php?t=HabbCrazy.NET&s=10&w=2
Here are some ways you can modify/use this script:
-Add a color attribute option
-Use this script for adding "stroke" effects to other types of true-type fonts
-Use it for generating page headers with volter font for a unique effect
-Any other way you see fit! Be creative!
Here's the code.
For example, create a file called text.php and enter in the following code.
<?php
/////////////////////////////////////////////////////////
// This script is free to use from the permission of //
// its author as long as this top portion stays intact.//
// //
// This script may be modified to your liking. //
// //
// AUTHOR: **David a.k.a Decoma (HabbCrazy.NET)** //
/////////////////////////////////////////////////////////
//this function is a special brew of the imagettftext() function with a "stroke" effect
function imagettftextoutline(&$im,$size,$angle,$x,$y,&$col,
&$outlinecol,$fontfile,$text,$width) {
for ($xc=$x-abs($width);$xc<=$x+abs($width);$xc++) {
for ($yc=$y-abs($width);$yc<=$y+abs($width);$yc++) {
$text1 = imagettftext($im,$size,$angle,$xc,$yc,-$outlinecol,$fontfile,$text);
}
}
// Draw the main text
$text2 = imagettftext($im,$size,$angle,$x,$y,-$col,$fontfile,$text);
}
header( "Content-type: image/png" ); //tells the browser that the content is a PNG file
$font = "volterb.ttf"; //specify font
//these are the attributes
$text = htmlspecialchars($_GET["t"]);
$fontsize = $_GET["s"];
$width = $_GET["w"];
//determine how many pixels (x and y) the text will take up
$size = imagettfbbox($fontsize, 0, $font, $text);
//then use those to determine the appropriate size of the image
$x = (abs($size[0] - $size[2])) + ($width*4);
$y = (abs($size[1] - $size[5])) + ($width*3);
//create the image and add a white background that is later removed
$im = imagecreatetruecolor($x, $y);
imageantialias($im, false);
$transparent = imagecolorallocate($im, 255, 255, 254);
imagefill($im, 0, 0, $transparent);
imagecolortransparent($im, $transparent); //set the white background to transparent
//determine the appropriate coordinates for the baseline of the font
$left = $size[0] + ($width*2);
$bottom = ($width*2) + $fontsize;
$white = imagecolorallocate( $im, 0xFF, 0xFF, 0xFF ); //font fill color
$black = imagecolorallocate( $im, 0x0, 0x0, 0x0 ); //stroke color
imagettftextoutline($im,$fontsize,0,$left,$bottom, $white,$black,$font,$text,$width); //create text
imagepng( $im ); //create a png image
imagedestroy( $im ); //clear the image from memory
?>
Now you can use it on your site like so
<img src="http://habbcrazy.net/djpanel/text.php?t=HabbCrazy.NET&s=20&w=3" />
OR
Simply access the URL directly at http://habbcrazy.net/djpanel/text.php?t=HabbCrazy.NET&s=20&w=3
Note the following attributes
t = input text to transform
s = size in pixels of the font
w = size in pixels of the "stroke" around the font
Enjoy!
-David
The only issue is that I can't completely get anti-aliasing disabled for really small fonts, but it's only 2 or 3 pixels that aren't noticeable unless you zoomed in and closely examined the piece.
Here are a few examples:
http://habbcrazy.net/djpanel/text.php?t=HabbCrazy.NET&s=20&w=3
http://habbcrazy.net/djpanel/text.php?t=HabbCrazy.NET&s=15&w=3
http://habbcrazy.net/djpanel/text.php?t=HabbCrazy.NET&s=10&w=2
Here are some ways you can modify/use this script:
-Add a color attribute option
-Use this script for adding "stroke" effects to other types of true-type fonts
-Use it for generating page headers with volter font for a unique effect
-Any other way you see fit! Be creative!
Here's the code.
For example, create a file called text.php and enter in the following code.
<?php
/////////////////////////////////////////////////////////
// This script is free to use from the permission of //
// its author as long as this top portion stays intact.//
// //
// This script may be modified to your liking. //
// //
// AUTHOR: **David a.k.a Decoma (HabbCrazy.NET)** //
/////////////////////////////////////////////////////////
//this function is a special brew of the imagettftext() function with a "stroke" effect
function imagettftextoutline(&$im,$size,$angle,$x,$y,&$col,
&$outlinecol,$fontfile,$text,$width) {
for ($xc=$x-abs($width);$xc<=$x+abs($width);$xc++) {
for ($yc=$y-abs($width);$yc<=$y+abs($width);$yc++) {
$text1 = imagettftext($im,$size,$angle,$xc,$yc,-$outlinecol,$fontfile,$text);
}
}
// Draw the main text
$text2 = imagettftext($im,$size,$angle,$x,$y,-$col,$fontfile,$text);
}
header( "Content-type: image/png" ); //tells the browser that the content is a PNG file
$font = "volterb.ttf"; //specify font
//these are the attributes
$text = htmlspecialchars($_GET["t"]);
$fontsize = $_GET["s"];
$width = $_GET["w"];
//determine how many pixels (x and y) the text will take up
$size = imagettfbbox($fontsize, 0, $font, $text);
//then use those to determine the appropriate size of the image
$x = (abs($size[0] - $size[2])) + ($width*4);
$y = (abs($size[1] - $size[5])) + ($width*3);
//create the image and add a white background that is later removed
$im = imagecreatetruecolor($x, $y);
imageantialias($im, false);
$transparent = imagecolorallocate($im, 255, 255, 254);
imagefill($im, 0, 0, $transparent);
imagecolortransparent($im, $transparent); //set the white background to transparent
//determine the appropriate coordinates for the baseline of the font
$left = $size[0] + ($width*2);
$bottom = ($width*2) + $fontsize;
$white = imagecolorallocate( $im, 0xFF, 0xFF, 0xFF ); //font fill color
$black = imagecolorallocate( $im, 0x0, 0x0, 0x0 ); //stroke color
imagettftextoutline($im,$fontsize,0,$left,$bottom, $white,$black,$font,$text,$width); //create text
imagepng( $im ); //create a png image
imagedestroy( $im ); //clear the image from memory
?>
Now you can use it on your site like so
<img src="http://habbcrazy.net/djpanel/text.php?t=HabbCrazy.NET&s=20&w=3" />
OR
Simply access the URL directly at http://habbcrazy.net/djpanel/text.php?t=HabbCrazy.NET&s=20&w=3
Note the following attributes
t = input text to transform
s = size in pixels of the font
w = size in pixels of the "stroke" around the font
Enjoy!
-David