note 11824 added to function.imagettfbbox.php

From: Date: Thu, 08 Mar 2001 19:04:40 +0000
Subject: note 11824 added to function.imagettfbbox.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-12051@lists.php.net to get a copy of this message
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 http://www.php.net/manual/nl/function.imagettfbbox.php

« previous php.notes (#12051) next »