|
|
imagepsbbox (PHP 3 >= 3.0.9, PHP 4, PHP 5) imagepsbbox -- Give the bounding box of a text rectangle using PostScript Type1 fonts Описаниеarray imagepsbbox ( string text, int font, int size [, int space [, int tightness [, float angle]]] )
Gives the bounding box of a text rectangle using PostScript Type1 fonts.
The bounding box is calculated using information available from character
metrics, and unfortunately tends to differ slightly from the results
achieved by actually rasterizing the text. If the angle is 0 degrees, you
can expect the text to need 1 pixel more to every direction.
Список параметров
text
fontCan be 1, 2, 3, 4, 5 for built-in
fonts (where higher numbers corresponding to larger fonts) or any of your
own font identifiers registered with imageloadfont().
size
size is expressed in pixels.
space
Allows you to change the default value of a space in a font. This
amount is added to the normal value and can also be negative.
Expressed in character space units, where 1 unit is 1/1000th of an
em-square.
tightness
tightness allows you to control the amount
of white space between characters. This amount is added to the
normal character width and can also be negative.
Expressed in character space units, where 1 unit is 1/1000th of an
em-square.
angle
angle is in degrees.
Возвращаемые значения
Returns an array containing the following elements:
ПримечанияЗамечание: Эта функция доступна только в
том случае, если PHP был скомпилирован с опцией
--enable-t1lib.
honza dot bartos at gmail dot com
23-Oct-2006 02:25
When using imagepsbbox, keep in mind, that meaning of y-coordinates is slightly different here. Y-coordinates returned by this function are related to the baseline of the text starting at point [0,0]. Positive values represent points ABOVE the baseline, negative values represent points BELOW the baseline. That is why the lower left y-coordinate is always smaller here than the upper right y-coordinate (these two coordinates are actualy values of metrics.descent and metrics.ascent - see T1Lib docs).
So when you want to place some text using coordinates of the top left corner (for example [100,100]), use this:
<?php
$x = 100;
$y = 100;
$text = "Dodge this";
$fontsize=18;
$font=imagepsloadfont("somefont.pfb");
list($lx,$ly,$rx,$ry) = imagepsbbox($text,$font,$fontsize);
imagepstext ($someimage, $text, $font, $fontsize, $somecolor, $somecolor, $x, $y + $ry);
?>
Hope it helps someone, I got stuck with this for a while.
daniel at dantec dot NO_SPAM dot nl
17-Apr-2002 09:23
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)
$text = "This is a sample text";
$fontsize=14;
$font=ImagePsLoadFont("/fonts/ariam___.pfb");
list($lx,$ly,$rx,$ry) = imagepsbbox($text,$font,$fontsize,0,0,0);
$textwidth = $rx - $lx;
$textheight = $ry - $ly;
$imh = $textheight + 20;
$imw = $textwidth + 40;
$im = imageCreate( $imw, $imh );
$black = ImageColorAllocate ($im, 0, 0, 0);
$white = ImageColorAllocate ($im, 255, 255, 255);
ImagePSText ($im, "$text", $font, $fontsize, $white, $white, 20, 20,'','','',4);
header("Content-type: image/jpeg");
ImageJPEG ($im,"",100);
Imagepsfreefont ( $font );
ImageDestroy ( $im );
?>
|