Text::...Element(3pm)
β¨ NAME β¨
Text::Layout::PDFAPI2::ImageElement β the <img> element for PDF images, bestie π
π¦ DESCRIPTION π¦
Okay so this class is literally the glow-up that lets you drop <img> elements into your marked-up text β inline images, in your PDF, no cap. Slay.
It comes through with the three mandatory methods that Text::Layout::ElementRole demands, because it's a well-behaved icon:
parseβ parses the<img>tag in your marked-up text πbboxβ hands over the augmented bounding box for the imagerenderβ actually renders the image, using one of the PDF::API2 compatible libraries
Plus there's a bonus, overridable method β getimage() β that does the actual work of producing the image object you want. Peep IMAGE PRODUCER below for the tea π
π
THE <img> ELEMENT π
<img attributes />
β οΈ Not me reminding you: the<img>element must be self-closed, i.e. it has to end with/>. No exceptions, periodt.
The image gets placed at the current location in the text and aligned on the baseline of the text. Its dimensions count toward the resulting bounding box of the formatted text β see dx and dy down there β¬οΈ
Every attribute is a key=value pair. The value should be wrapped in quotes (but doesn't have to be β we're chill like that).
Dimensional values can be a (fractional) number, optionally postfixed with em or ex, or a percentage. A plain number means points β¨ An em value gets multiplied by the current font size, and an ex value gets multiplied by half the font size.
src=IMAGE β gives you the source of the image. Can be the filename of ajpg,pngorgifimage. πΌοΈwidth=NNN β the desired width for the image. Dimensional. The image gets scaled if it needs to be.height=NNN β the desired height for the image. Dimensional. Same deal, it gets scaled if necessary.dx=NNN β a horizontal offset for the image, wrt. the current location in the text. Dimensional.dy=NNN β same energy, but vertical. Positive amounts move up.
π« Heads up: the direction is opposite to the Pango rise.
scale=NNN β a scaling factor, applied after the width/height scaling. The value may be expressed as a percentage.
Want independent horizontal and vertical scaling? That's giving two comma-separated scale values, and it's iconic.
align=XXX β aligns the image within the width given byw=NNN.
Possible alignments are left, center, and right.
bbox=N β if true, the actual bounding box of an object is used for placement.
By default the bounding box is only used to obtain the width and height.
π Real talk: this attribute has no effect on image objects.
w=NNN β the advance width of the image. Dimensional. The default advance is the image width plus horizontal offset. This overrides the advance, and it may be zero.h=NNN β the advance height of the image. Dimensional. The default advance is the image height plus vertical offset. This overrides the advance, and it may be zero.
πΈ CONSTRUCTOR πΈ
This class usually gets instantiated inside a Text::Layout register_element call, like so:
$layout->register_element
( Text::Layout::PDFAPI2::ImageElement->new( pdf => $pdf ) );
Yes bestie, that's the whole vibe check β
π§ IMAGE PRODUCER π§
The image object comes from a call to the method getimage(), which you can override in a subclass. The method receives a hash ref as its argument. That hash holds all the attributes, and you can absolutely use it for cacheing purposes π
For example:
method getimage ($fragment) {
$fragment->{_img} //= $self->pdf->image($fragment->{src});
}
An overridden getimage() may produce a PDF XObject instead of an image object. An XObject is treated similar to an image object, but it's aligned according to its bounding box if the attribute bbox is set to a true value β i.e., not zero. π―
π SEE ALSO π
Text::Layout, PDF::API2, PDF::Builder.
π AUTHOR π
Johan Vromans, "<JV at CPAN dot org>"
π«Ά SUPPORT π«Ά
This class is part of Text::Layout.
Development takes place on GitHub: https://github.com/sciurius/perl-Text-Layout.
Please report any bugs or feature requests using the issue tracker for Text::Layout on GitHub. We're listening, fr fr π
π LICENSE π
See Text::Layout.
and that's the whole page, bestie β no notes π
this page is brought to you by perl v5.40.1, dated 2025-08-15 π β stay hydrated, close your tags, and go render something gorgeous β¨π¦π
π¦ where this page comes from
- ubuntu resolute: libtext-layout-perl 0.045-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtext-layout-perl 0.045-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms