PDF::Bu...age::PNG(3)
β¨ PDF::Builder::Resource::XObject::Image::PNG β¨
okay bestie, sit down, hydrate, and let me tell you about PDF::Builder::Resource::XObject::Image::PNG β the support routines for the PNG image library, and yes, it's running on pure Perl code, no cap. π
She inherits from PDF::Builder::Resource::XObject::Image, so all that parent energy is already in the room. π
πΈ METHODS πΈ
π new
$res = PDF::Builder::Resource::XObject::Image::PNG->new($pdf, $file, %opts)
This one hands you back a whole PNG-image object, literally. Here's the vibe check on the args:
$pdfβ the PDF object you're adding to π«Ά$fileβ the input PNG file$nameβ optional, and it's the name of the new parent image object. Defaults toPxAAA. cute.
Now, real talk: if the Image::PNG::Libpng package is installed, the PNG_IPL library gets used instead of the PNG library. π And in that case? You can force the PNG library to be used anyway with the "nouseIPL" flag (peep the Builder documentation for image_png() for the deets).
the opts bestie π
'notrans' => 1β no transparency, periodt. Ignores the tRNS chunk if it's provided, and ignores the Alpha channel if it's provided.'name' => 'string'β this is the name you can give to the PNG image object. The default isPxnnnn.
β οΈ Remember that you need to invoke theimage_pngmethod fromBuilder.pmin order to use this functionality. Don't skip that step, I'm begging. π
π¦ Supported PNG types π¦
- (0) Gray scale of depth 1, 2, 4, or 8 bits per pixel (2, 4, 16, or 256 gray levels). 16 bpp is not currently supported (a PNG with 16 bpp is a fatal error). Full transparency (of one 8-bit gray value) via the
tRNSchunk is allowed, unless thenotransoption specifies that it be ignored. - (2) RGB 24-bit truecolor with 8 bits per sample (16.7 million colors). 16 bps is not currently supported (a PNG with 16 bps is a fatal error). Full transparency (of one 3x8-bit RGB color value) via the
tRNSchunk is allowed, unless thenotransoption specifies that it be ignored. - (3) Palette color with 1, 2, 4, or 8 bits per pixel (2, 4, 16, or 256 color table/palette entries). 16 bpp is not currently supported by PNG or PDF. Partial transparency (8-bit Alpha) for each palette entry via the
tRNSchunk is allowed, unless thenotransoption specifies that it be ignored (all entries fully opaque). - (4) Gray scale of depth 8 bits per pixel plus 8-bit Alpha channel (256 gray levels and 256 levels of transparency). 16 bpp is not currently supported (a PNG with 16 bpp is a fatal error). The Alpha channel is ignored if the
notransoption is given. ThetRNSchunk is not permitted. - (6) RGB 24-bit truecolor with 8 bits per sample (16.7 million colors) plus 8-bit Alpha channel (256 levels of transparency). 16 bps is not currently supported (a PNG with 16 bps is a fatal error). The Alpha channel is ignored if the
notransoption is given. ThetRNSchunk is not permitted.
In all cases, 16 bits per sample are not implemented. A fatal error will be returned if a PNG image with 16-bps data is supplied. π«
The code is assuming standard "network" bit ordering (Big Endian). Interlaced (progressive) display images are not supported. If you need 16 bps or interlaced images, use the PNG_IPL version instead. π«
The transparency chunk (tRNS) will specify one gray level entry or one RGB entry to be treated as transparent (Alpha = 0). For palette color, up to 256 palette entry 8-bit Alpha values are specified (256 levels of transparency, from 0 = transparent to 255 = opaque). π
Only a limited number of chunks are handled: IHDR, IDAT (internally), PLTE, tRNS, and IEND (internally). All other chunks are ignored at this time. Certain filters and compressions applied to data will be handled, but there may be unsupported methods. π
π usesLib
$mode = $png->usesLib()
Returns 1 if Image::PNG::Libpng is installed and used, 0 if it's not installed, or -1 if it's installed but not used (the nouseIPL option was given to "image_png"). Three moods, one number. π
β οΈ Caution: this method can only be used after the image object has been created. It can't tell you whetherImage::PNG::Libpngis available in advance of actually using it, in case you want to use some functionality available only in PNG_IPL. See thePDF::BuilderLA_IPL()call if you need to know in advance. π
that's the whole page, bestie β go forth and slay those PNGs π§ββοΈπβ¨
this was brought to you by perl v5.42.0, dated 2026-01-17, from the User Contributed Perl Documentation collection. mwah, take care of her π«Άπ
π¦ where this page comes from
- fedora 44: perl-PDF-Builder 3.028-2.fc44 Β· LGPL-2.1-or-later AND LGPL-2.1-only AND MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms