note 20840 added to function.imagepsbbox
| From: | daniel at dantec dot NO_SPAM dot nl | Date: | Thu, 18 Apr 2002 01:23:46 +0000 |
| Subject: | note 20840 added to function.imagepsbbox | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-29513@lists.php.net to get a copy of this message | ||
When using imagepsbbox, you are probably trying to do something like creating a button with text, so
that the button is large enough for the text...
Below is a very simple example of making a black button just big enough to display white text on it.
<?php
//if text is no variable set sample text
if (!$text)
$text = "This is a sample text";
// set the font size
$fontsize=14;
// load the font to use
$font=ImagePsLoadFont("/fonts/ariam___.pfb");
//get the left lower corner and the right upper
list($lx,$ly,$rx,$ry) = imagepsbbox($text,$font,$fontsize,0,0,0);
// calculate the size of the text
$textwidth = $rx - $lx;
$textheight = $ry - $ly;
// make an image 40 pixels wider and 20 pixels higher than the text
$imh = $textheight + 20;
$imw = $textwidth + 40;
$im = imageCreate( $imw, $imh );
//define colors, first color is used as background color!
$black = ImageColorAllocate ($im, 0, 0, 0);
$white = ImageColorAllocate ($im, 255, 255, 255);
//create the text (with the same parameters as imagepsbbox!)
ImagePSText ($im, "$text", $font, $fontsize, $white, $white, 20,
20,'','','',4);
//send the header
header("Content-type: image/jpeg");
// create the image
ImageJPEG ($im,"",100);
//destroy the image & font to free memory
Imagepsfreefont ( $font );
ImageDestroy ( $im );
?>
--
http://www.php.net/manual/en/function.imagepsbbox.php
http://master.php.net/manage/user-notes.php?action=edit+20840
http://master.php.net/manage/user-notes.php?action=delete+20840
http://master.php.net/manage/user-notes.php?action=reject+20840