phpdftk API Documentation

PngParser
in package

FinalYes

Parse PNG IHDR chunk for dimensions, bit depth, and color type.

Also extracts ICC profiles from iCCP chunks. PNG alpha channels are detected since PDF handles transparency via SMask, not inline.

Table of Contents

Methods

decodeAlphaPng()  : array{colour: string, alpha: string, width: int, height: int, components: int}|null
Decode an 8-bit alpha PNG (color type 4 = grayscale+alpha, type 6 = RGB+alpha) into separate colour and alpha streams.
decodeIndexedPng()  : array{colour: string, alpha: ?string, width: int, height: int}|null
Decode an 8-bit indexed-colour PNG (color type 3) into the separate colour + alpha streams a PDF Image XObject embeds.
extractIdatData()  : string|null
Extract the concatenated `IDAT` chunk payload from a PNG.
parse()  : ImageInfo
parseFile()  : ImageInfo

Methods

decodeAlphaPng()

Decode an 8-bit alpha PNG (color type 4 = grayscale+alpha, type 6 = RGB+alpha) into separate colour and alpha streams.

public static decodeAlphaPng(string $data) : array{colour: string, alpha: string, width: int, height: int, components: int}|null

The PDF caller then emits the colour as the main Image XObject and the alpha as an /SMask reference attached to it. Returns null for non-alpha PNGs, non-8-bit depths, or any decode failure (corrupt IDAT, bad filter byte, etc.).

Output streams are raw (uncompressed) per-pixel bytes — colour: 1 byte/px (grayscale) or 3 bytes/px (RGB). alpha: 1 byte/px (grayscale always).

The caller is expected to FlateDecode-compress them before embedding in the PDF.

Parameters
$data : string
Return values
array{colour: string, alpha: string, width: int, height: int, components: int}|null

decodeIndexedPng()

Decode an 8-bit indexed-colour PNG (color type 3) into the separate colour + alpha streams a PDF Image XObject embeds.

public static decodeIndexedPng(string $data) : array{colour: string, alpha: ?string, width: int, height: int}|null

Walks the IDAT data through PNG filter reversal, indexes each pixel into the PLTE palette, and (when the optional tRNS chunk is present) looks up per-palette-index alpha.

Returns null for non-indexed PNGs, unsupported bit depths (anything outside 1 / 2 / 4 / 8), missing PLTE, or any decode failure.

Output: colour = 3 bytes/px (RGB). alpha = 1 byte/px when tRNS is present; null when the palette is fully opaque (the caller skips the SMask).

Parameters
$data : string
Return values
array{colour: string, alpha: ?string, width: int, height: int}|null

extractIdatData()

Extract the concatenated `IDAT` chunk payload from a PNG.

public static extractIdatData(string $data) : string|null

The payload is already DEFLATE-compressed PNG-filter-coded pixel data, suitable for embedding in a PDF Image XObject with /Filter /FlateDecode + /DecodeParms <<Predictor 15 Columns W Colors N BitsPerComponent B>> — PDF readers decompress + unfilter via the predictor without an intermediate raw-RGB buffer.

Returns null when the PNG signature is invalid or no IDAT chunks are present.

Parameters
$data : string
Return values
string|null

        
On this page

Search results