module

PNGGIF

Pure-Crystal PNG / APNG / GIF reader.

Decodes an image file (or in-memory buffer) into RGBA bitmaps and terminal-cell maps. Ported from Blessed's bundled vendor/tng.js (https://github.com/chjj/tng, MIT). Extracted from Crysterm into a standalone shard so it can be reused independently of the TUI toolkit.

PNG decompression uses Crystal's stdlib Compress::Zlib; GIF uses a ported LZW decoder. JPEG and other formats are converted to PNG via ImageMagick's convert if it is available.

Constants

PNG_SIGNATURE = UInt8.static_array(137, 80, 78, 71, 13, 10, 26, 10)

The 8-byte PNG file signature.

VERSION = "0.1.0"

Class methods

encode_apng(frames : Array(Tuple(Bitmap, Int32)), num_plays : Int32 = 0) : Bytes

Encodes frames ({bitmap, delay_ms}) as an animated PNG (APNG) and returns the file bytes. num_plays is the loop count (0 = loop forever). The first frame doubles as the still IDAT (so non-APNG viewers show it). All frames must share the canvas size of the first frame.

Source
encode_apng(frames : Array(Tuple(Bitmap, Int32)), io : IO, num_plays : Int32 = 0) : Nil

Encodes frames ({bitmap, delay_ms}) as an animated PNG (APNG) and returns the file bytes. num_plays is the loop count (0 = loop forever). The first frame doubles as the still IDAT (so non-APNG viewers show it). All frames must share the canvas size of the first frame.

Source
encode_png(bmp : Bitmap, io : IO) : Nil

Encodes bmp as a still PNG, writing the file bytes to io.

Source
encode_png(bmp : Bitmap) : Bytes

Encodes bmp as a still PNG and returns the file bytes.

Source

Nested types