注释

参见

User Contributed Notes 4 notes

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:

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:

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 textif (!$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 upperlist($lx,$ly,$rx,$ry) = imagepsbbox($text,$font,$fontsize,0,0,0);