pngmeta

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeCodeIHDR = 1229472850
	TypeCodeIDAT = 1229209940
	TypeCodeIEND = 1229278788
	TypeCodepHYs = 1883789683
)

Variables

View Source
var PNGSignature = []byte{137, 80, 78, 71, 13, 10, 26, 10}

Functions

func ChunkTypeToInt

func ChunkTypeToInt(str string) uint32

Fast conversion of chunk type string to equivalent uint32.

func IntToChunkType

func IntToChunkType(i uint32) string

Fast conversion of type integer to equivalent string of 4 ASCII characters.

func NewPhysData

func NewPhysData(ppm float64) []byte

Returns chunk data for a pHYs (physical dimensions) chunk, given a value for pixels-per-meter.

Types

type Chunk

type Chunk struct {
	Length, Type, CRC uint32
	Data              []byte
}

func ReadChunk added in v0.1.4

func ReadChunk(r io.Reader, hasher hash.Hash32) (c Chunk, err error)

Read a single chunk from `r`, using `hasher` which must be an IEEE CRC-32 instance.

func ReadChunks added in v0.1.4

func ReadChunks(r io.Reader) (chunks []Chunk, err error)

Read all chunks from given reader.

func ReadIHDRChunk added in v0.1.4

func ReadIHDRChunk(r io.Reader) (c Chunk, err error)

Only read the IHDR chunk from the file, and nothing more. Can be beneficial for high-performance metadata checking.

func (Chunk) Checksum

func (c Chunk) Checksum(hasher hash.Hash32) (uint32, error)

func (Chunk) Properties

func (c Chunk) Properties() (anc, priv, res, copy bool)

Return values of chunk type's property bits.

func (Chunk) String

func (c Chunk) String() string

func (Chunk) TypeName

func (c Chunk) TypeName() string

func (Chunk) Write

func (c Chunk) Write(w io.Writer) error

type PNG

type PNG struct {
	// contains filtered or unexported fields
}

A collection of PNG data/metadata chunks and associated useful operations.

func LoadPNG

func LoadPNG(r io.Reader) (*PNG, error)

Read serialized PNG from given reader into regions of chunks to be operated on or queried.

func (*PNG) Chunks

func (p *PNG) Chunks() []Chunk

Return chunks of all regions as one single, contiguous chunk slice.

func (*PNG) FilterChunks added in v0.2.0

func (p *PNG) FilterChunks(chunkType uint32, region Region) (matched []Chunk)

Return all chunks which match a given type code within the given region.

func (*PNG) FirstChunkOfType added in v0.2.0

func (p *PNG) FirstChunkOfType(chunkType uint32, region Region) (Chunk, error)

Return the first chunk matching the given type code within the given region.

func (*PNG) InsertChunk added in v0.2.0

func (p *PNG) InsertChunk(chunkType uint32, data []byte, region Region) error

Insert a chunk of the given type, containing the given data bytes, into the given region.

func (*PNG) RegionSlice

func (p *PNG) RegionSlice(region Region) []Chunk

Return the chunk slice corresponding to the given region.

func (*PNG) UpsertChunk added in v0.2.1

func (p *PNG) UpsertChunk(chunkType uint32, data []byte, region Region) error

Replaces the data for the first chunk of the given type, or adds as a new chunk if one does not yet exist.

func (*PNG) Write

func (p *PNG) Write(w io.Writer) error

type PNGHeader

type PNGHeader struct {
	Width, Height                  uint32
	BitDepth, ColorType            uint8
	Compression, Filter, Interlace uint8
}

See: https://exiftool.org/TagNames/PNG.html#ImageHeader

func ParseIHDRChunk

func ParseIHDRChunk(chunkIHDR Chunk) (h PNGHeader)

type Region

type Region = uint8
const (
	// Represents pre-data-chunk region (usually metadata chunks).
	RegionBegin Region = iota
	// Represents data region (exclusively IDAT chunks).
	RegionData
	// Represents post-data-chunk region (usually just IEND chunk).
	RegionEnd
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL