class

PDF::Images::PNG

Inherits PDF::Images::Base < Reference < Object

PNG image handler with alpha channel support.

PNG images are decoded using stumpy_png and re-encoded with FlateDecode for PDF embedding. Alpha channels are extracted as separate soft mask images for transparency support.

Usage

png = PDF::Images::PNG.load("logo.png")
png.width       # => 200
png.height      # => 100
png.has_alpha?  # => true

Constructors

load(path : String) : PNG

Load PNG from file path

Source
load(io : IO) : PNG

Load PNG from IO

Source
load(data : Bytes) : PNG

Load PNG from bytes

Source
new(rgb_data : Bytes, alpha_data : Bytes | Nil, width : Int32, height : Int32, has_alpha : Bool)
Source

Instance methods

alpha_data

Alpha channel data (if present)

Source
bits_per_component

Bits per color component (typically 8)

Source
color_space

PDF color space name (/DeviceRGB, /DeviceGray, /DeviceCMYK)

Source
has_alpha

Whether this PNG has meaningful transparency

Source
has_alpha?

Whether this image has transparency (alpha channel)

Source
height
Source
rgb_data

Decoded RGB pixel data (no alpha)

Source
soft_mask_stream

Create the soft mask stream for transparency

Source
to_stream

Create the main image stream (RGB data only)

Source
width

Image dimensions

Source