Imager...::BBox(3pm)
π NAME π
Okay bestie, so Imager::Font::BBox β it's the object class that hands you back a whole little vibe check of info about a string of text, aka its bounding box. That's the name, that's the manual (it lives in the Perl User Contributed Documentation corner of the world, section 3pm, iykyk). β¨
πΈ SYNOPSIS πΈ
Here's the whole flow, literally copy-paste blessed:
use Imager::Font;
# get the object
my $font = Imager::Font->new(...);
my $bbox = $font->bounding_box(string=>$text, size=>$size);
# methods
my $start = $bbox->start_offset;
my $left_bearing = $bbox->left_bearing;
my $right_bearing = $bbox->right_bearing;
my $end = $bbox->end_offset;
my $gdescent = $box->global_descent;
my $gascent = $bbox->global_ascent;
my $ascent = $bbox->ascent;
my $decent = $bbox->descent;
my $total_width = $bbox->total_width;
my $fheight = $bbox->font_height;
my $theight = $bbox->text_height;
my $display_width = $bbox->display_width;
(And yes, $box vs $bbox β that's in the original, don't come for me π it's a vibe, not a typo I invented.)
π¦ DESCRIPTION π¦
So here's the tea: objects of this class are what you get returned to you by the Imager::Font bounding_box() method when you call it in scalar context. π
The whole point? Making all that info from the method way more accessible. Which, honestly, slay. π«Ά
π METHODS π
start_offset(), neg_width, left_bearing
Returns the horizontal offset from the drawing location you picked to the left edge of the very first character drawn. If this number's positive, your first glyph is sitting to the right of the drawing location. β¨
- The alias
neg_width()exists to match thebounding_box()documentation for list context. - The alias
left_bearing()exists to match font terminology.
Both aliases = same energy, different label. π
advance_width()
The advance width of the string β if the driver supports that. If it doesn't, it's just the same as end_offset. No cap.
right_bearing
The distance from the right side of the last glyph to the end of the advance point. π―
Heads up bestie: if the glyph overflows the right side of the advance width, this value goes negative.
display_width
The distance from the left-most pixel of the left-most glyph all the way to the right-most pixel of the right-most glyph. π
Equals advance_width - left_bearing - right_bearing β and it's literally implemented that way, they said so.
global_descent()
The lowest position (relative to the font baseline) that any character in the font reaches in the character cell. Normally negative. π
Not me finding out at least one font out there has reported a positive number for this. π Weird but true.
global_ascent()
The highest position (relative to the font baseline) that any character in the font reaches in the character cell. Normally positive. π
descent()
The lowest position (relative to the font baseline) that any character in the supplied string reaches. Negative whenever any character's glyph dips below the baseline. π
ascent()
The highest position (relative to the font baseline) that any character in the supplied string reaches. Positive if any character's glyph reaches above the baseline. π¦
font_height()
The maximum displayed height of any string using this font. The ceiling. The limit. π
text_height()
The displayed height of the supplied string. Specifically yours. π
π OBSOLETE METHODS π
Okay so real talk: these methods include bugs kept for backwards compatibility and genuinely shouldn't be used in new code. Like, don't. π«
total_width()
The total displayed width of the string.
New code should use display_width() instead. Periodt.
This one depends on end_offset(), and it's limited by its backward compatibility.
end_offset, pos_width
The offset from the drawing location you picked to the right edge of the last character drawn. Should always be positive. β¨
You can use the alias pos_width() if you're used to the bounding_box() documentation for list context.
For backwards compatibility, this method returns the maximum of the advance width and the offset of the right edge of the last glyph. Yes, really. That's the deal. π«
βοΈ INTERNAL FUNCTIONS βοΈ
new(...)
Called by Imager::Font->bounding_box() to create the object. That's it, that's the job β internal business, nothing for you here bestie. π
π BUGS π
So it doesn't reproduce the functionality you'd get using the x and y parameters to Imager::Font->bounding_box(). π And they genuinely considered this:
my ($left, $top, $right, $bottom) = $box->offset(x=>$x, y=>$y)
...but honestly that's about as clumsy as the original. π So, yeah. Noted, not fixed.
π AUTHOR π
Tony Cook <tony@develop-help.com> β an icon, a legend, the moment. π
π SEE ALSO π
That's the whole page, bestie β go forth and measure your glyphs with confidence. π
This masterpiece of a manual comes to you as perl v5.42.3, dated 2026-08-19 β write that down, cite it in your group chat, it's giving documentation excellence. πβ¨
π¦ where this page comes from
- ubuntu stonking: libimager-perl 1.035+dfsg-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms