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 to PxAAA. 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 is Pxnnnn.
⚠️ Remember that you need to invoke the image_png method from Builder.pm in 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 tRNS chunk is allowed, unless the notrans option 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 tRNS chunk is allowed, unless the notrans option 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 tRNS chunk is allowed, unless the notrans option 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 notrans option is given. The tRNS chunk 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 notrans option is given. The tRNS chunk 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 whether Image::PNG::Libpng is available in advance of actually using it, in case you want to use some functionality available only in PNG_IPL. See the PDF::Builder LA_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