PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

imagepsencodefont> <imagepolygon
Last updated: Fri, 22 Aug 2008

view this page in

imagepsbbox

(PHP 4, PHP 5)

imagepsbboxEntregar la cada circundante de un rectángulo de texto usando fuentes PostScript Type1

Descripción

array imagepsbbox ( string $texto , int $fuente , int $tamanyo [, int $espacio ], int $ajuste , float $angulo )

Entrega la caja circundante de un rectángulo de texto usando fuentes PostScript Type1.

La caja circundante es calculada usando información disponible de las métricas de caracteres, y desafortunadamente tiende a diferir un poco de los resultados conseguidos al rasterizar el texto. Si el ángulo es 0 grados, puede esperar que el texto necesite 1 pixel más en cada dirección.

Lista de parámetros

texto

font

Can be 1, 2, 3, 4, 5 for built-in fonts in latin2 encoding (where higher numbers corresponding to larger fonts) or any of your own font identifiers registered with imageloadfont().

tamanyo

tamanyo es expresado en pixeles.

espacio

Le permite modificar el valor predeterminado de un espacio en una fuente. Esta cantidad es agregada al valor normal y puede ser negativa también. Expresada en unidades de espacio de caracter, en donde 1 unidad es 1 milésimo de un cuadro em.

ajuste

ajuste le permite controlar la cantidad de espacio en blanco entre caracteres. Esta cantidad es agregada al ancho normal de caracter y puede ser negativa también. Expresada en unidades de espacio de caracter, en donde 1 unidad es 1 milésimo de un cuadro em.

angulo

angulo en grados.

Valores retornados

Devuelve una matriz que contiene los siguientes elementos:

0 coordenada x izquierda
1 coordenada y superior
2 coordenada x derecha
3 coordenada y inferior

Notes

Note: Esta funcion esta disponible solamente si PHP se ha compilado usando la opcion --with-t1lib[=DIR].

Ver también



imagepsencodefont> <imagepolygon
Last updated: Fri, 22 Aug 2008
 
add a note add a note User Contributed Notes
imagepsbbox
eikie
05-May-2008 09:32
in my code below, there is an error!

replace
$w += abs($bb[3])-abs($bb[1]); // accumulate width

with
$w += abs($bb[2])-abs($bb[0]); // accumulate width

also after
$bb = imagepsbbox($c, $font, $size); // calculate width

you can add this line because spaces make odd values...
if ($c == ' ' ) $bb = imagepsbbox('i', $font, $size);
eikie
05-May-2008 08:34
I have a given image width and need to render a long string on that image. By using the following function I'm, able to get an array of strings which each will fit into the images width. It might need a lot of CPU time, but it's cool:

// Function to return an Array of Strings
// Arguments: String to be wrapped, maximum width in pixels of each line, font and fontsize
function imgwordwrap($s, $maxWidth, $font, $size) {
  // Make an empty ArrayList
  $a = array();
  $w = 0;    // Accumulate width of chars
  $i = 0;      // Count through chars
  $rememberSpace = 0; // Remember where the last space was
  // As long as we are not at the end of the String
  while ($i < strlen($s)) {
    // Current char
    $c = substr($s, $i, 1);
    $bb = imagepsbbox($c, $font, $size); // calculate width
    $w += abs($bb[3])-abs($bb[1]); // accumulate width
    if ($c == ' ') $rememberSpace = $i; // Are we a blank space?
    if ($w > $maxWidth) {  // Have we reached the end of a line?
      $sub = substr($s,0,$rememberSpace); // Make a substring
            // Chop off space at beginning
            if (substr($sub,0,1)==' ') $sub = substr($sub,1);
      // Add substring to the array
      $a[] = $sub;
      // Reset everything
      $s = substr($s,$rememberSpace);
      $i = 0;
      $w = 0;
    }
    else {
      $i++;  // Keep going!
    }
  }
 
  // Take care of the last remaining line
  trim($s);
  if (substr($s,0,1)==' ') $s = substr($s,1);
  $a[] = $s;
 
  return $a;
}
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 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 );

?>

imagepsencodefont> <imagepolygon
Last updated: Fri, 22 Aug 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites