note 11824 deleted from function.imagettfbbox by sniper
| From: | sniper@php.net | Date: | Fri, 07 Nov 2003 12:39:58 +0000 |
| Subject: | note 11824 deleted from function.imagettfbbox by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-60072@lists.php.net to get a copy of this message | ||
Note Submitter: rob@OhReally.com
----
center horizontally and vertically
<?
# variables
$pic = "header_kln_blanco_top.gif";
$fontfile = "Arial.ttf";
$fontsize = "12";
$fontcolor = "#000000";
$textangle = "0";
$text = (isset($text) ? rawurldecode($text) : "OhReally"); # should be set in
query_string
# create pic and fontcolor
$pic = imagecreatefromgif($pic);
$fontcolor = str_replace("#", "", $fontcolor);
$fontcolor = imagecolorallocate($pic, hexdec(substr($fontcolor, 0, 2)), hexdec(substr($fontcolor, 2,
2)), hexdec(substr($fontcolor, 4, 2)));
# calculate start position
$picwidth = imagesx($pic);
$picheight = imagesy($pic);
list($pos_blx, $pos_bly, $pos_brx, $pos_bry, $pos_trx, $pos_try, $pos_tlx, $pos_tly) =
imagettfbbox($fontsize, $textangle, $fontfile, $text);
$textwidth = $pos_brx - $pos_blx;
$textheight = $pos_bly - $pos_tly;
$start_x = ($picwidth - $textwidth) / 2;
$start_y = (($picheight - $textheight) / 2) + $textheight;
# write text and output image
imagettftext($pic, $fontsize, $textangle, $start_x, $start_y, $fontcolor, $fontfile, $text);
header("content-type: image/gif");
imagegif($pic);
imagedestroy($pic);
?>
and you call it like this:
<IMG SRC="thepic.php?text=<? echo urlencode($mytext); ?>">
at your service
Rob