ChunkPNG (chunk_png v1.0.347)
Library for manipulating metadata in PNG files.
PNG files consist of a magic number, a mandatory header chunk, then a list of optional chunks. This library splits the file into a list of chunks with a cursor and allows you to insert and remove chunks.
A standard PNG may consist of:
- magic number (8 bytes)
- IHDR - mandatory first chunk of a PNG datastream
- PLTE - pallete for indexed PNG images
<--
- IDAT - image data chunk(s)
- IEND - image trailer, the last in a PNG datastream
Consider the use case of inserting copyright metadata. After parsing your image you receive a list of chunks in the form of a list-zipper which is a tuple of the list of chunks up until IDHR, then the focus (probably PLTE), then the remaining list of chunks after the focus. You may immediately insert your new chunks to the left of the focus and after the IHDR, or navigate to the end and append new chunks there.
There are three forms of textual chunks:
tEXt
- simple key-value using the Latin-1 character setiTXt
- simple key-value using UTF-8 encoding with optional value compressionzTXt
- equivalent totEXt
but using deflate compression for large text blocks
When finished the list of chunks can be written out to a file or a buffer.
Link to this section Summary
Functions
Insert a chunk to the left of the focus
Parse a PNG from in-memory buffer
Parse a PNG file into a zipper of a list of chunks
Write a chunk zipper as a binary PNG datastream
Write a chunk zipper to a PNG file
Link to this section Types
zipper()
@type zipper() :: {[ChunkPNG.Chunk.t()], ChunkPNG.Chunk.t(), [ChunkPNG.Chunk.t()]}
Link to this section Functions
insert_left(arg, chunk)
Insert a chunk to the left of the focus
parse_buffer(data)
Parse a PNG from in-memory buffer
parse_file!(path)
Parse a PNG file into a zipper of a list of chunks
write_buffer(arg)
Write a chunk zipper as a binary PNG datastream
write_file(arg, path)
Write a chunk zipper to a PNG file