The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
Simple Dynamic Text
Posted by: Stephen | January 26, 2008 @ 4:40pm
PHP Code
[
Download
]
<?php Header("Content-type: image/gif"); // $s is the font size in pixels if(!isset($_GET['s'])) {$s = 32;} else {$s = $_GET['s'];} // $text is the text to display if(!isset($_GET['text'])) {$text = "PHP is cool!";} else {$text = $_GET['text'];} // $f_path is the path to your font file $f_path = "c:/windows/fonts/times.ttf"; $size = imagettfbbox($s,0,$f_path,$text); $dx = abs($size[2]-$size[0]); $dy = abs($size[5]-$size[3]); $xpad=9; $ypad=9; $im = imagecreate($dx+$xpad,$dy+$ypad); $blue = ImageColorAllocate($im, 0x2c,0x6D,0xAF); $black = ImageColorAllocate($im, 0,0,0); $white = ImageColorAllocate($im, 255,255,255); ImageRectangle($im,0,0,$dx+$xpad-1,$dy+$ypad-1,$black); ImageRectangle($im,0,0,$dx+$xpad,$dy+$ypad,$white); ImageTTFText($im, $s, 0, (int)($xpad/2)+1, $dy+(int)($ypad/2), $black, "$f_path", $text); ImageTTFText($im, $s, 0, (int)($xpad/2), $dy+(int)($ypad/2)-1, $white, "$f_path", $text); ImageGif($im); ImageDestroy($im); ?>
Syntax Highlighting
[
Open in new window
]
Author Comments
This script will simply calculate the size of a single-line text input and output the text as a graphic.
This code is updated from
this script
.
Rating
4.70 / 8
149 Votes