format

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package format provides image container detection and metadata extraction/injection for all supported formats.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SupportsWrite

func SupportsWrite(f FormatID) bool

SupportsWrite reports whether the library can inject metadata into files of the given format (i.e., Write and WriteFile will not return UnsupportedFormatError).

Types

type Container

type Container interface {
	Extract(r io.ReadSeeker) (rawEXIF, rawIPTC, rawXMP []byte, err error)
	Inject(r io.ReadSeeker, w io.Writer, rawEXIF, rawIPTC, rawXMP []byte) error
}

Container is the interface that every format-specific handler must satisfy. It is the only boundary between the container layer and the dispatcher.

Extract reads raw metadata payloads from r without parsing them. Any of the returned slices may be nil if that metadata type is absent.

Inject reads the original image from r, replaces the metadata payloads with rawEXIF, rawIPTC, and rawXMP respectively (nil means remove), and writes the result to w. Image data and unrelated segments are preserved byte-for-byte.

type FormatID

type FormatID uint8

FormatID identifies the container format of an image file.

const (
	FormatUnknown FormatID = iota
	FormatJPEG
	FormatTIFF
	FormatPNG
	FormatHEIF // includes HEIC and other non-AVIF ISOBMFF image brands
	FormatWebP
	FormatCR2
	FormatCR3
	FormatNEF
	FormatARW
	FormatDNG
	FormatORF
	FormatRW2
	FormatAVIF // AVIF (AV1 Image File Format, ISO 23008-12)
)

FormatUnknown and related constants enumerate all image container formats supported by the library. Format detection is by magic bytes, never by file extension (CLAUDE.md §1).

func Detect

func Detect(r io.ReadSeeker) (FormatID, error)

Detect reads up to magicLen bytes from r (without consuming them) and returns the detected FormatID. For TIFF-family files it reads additional bytes to distinguish NEF, ARW, and DNG from generic TIFF.

func (FormatID) String

func (f FormatID) String() string

String returns a human-readable name for the format.

Directories

Path Synopsis
Package heif implements extraction and injection of EXIF and XMP metadata within HEIF/HEIC files (ISO 23008-12 / ISO 14496-12 ISOBMFF).
Package heif implements extraction and injection of EXIF and XMP metadata within HEIF/HEIC files (ISO 23008-12 / ISO 14496-12 ISOBMFF).
Package jpeg implements extraction and injection of EXIF, IPTC, and XMP metadata segments within JPEG files.
Package jpeg implements extraction and injection of EXIF, IPTC, and XMP metadata segments within JPEG files.
Package png implements extraction and injection of EXIF and XMP metadata within PNG files.
Package png implements extraction and injection of EXIF and XMP metadata within PNG files.
raw
arw
Package arw implements metadata extraction for Sony ARW files.
Package arw implements metadata extraction for Sony ARW files.
cr2
Package cr2 implements metadata extraction for Canon CR2 files.
Package cr2 implements metadata extraction for Canon CR2 files.
cr3
Package cr3 implements metadata extraction for Canon CR3 files.
Package cr3 implements metadata extraction for Canon CR3 files.
dng
Package dng implements metadata extraction for Adobe DNG files.
Package dng implements metadata extraction for Adobe DNG files.
nef
Package nef implements metadata extraction for Nikon NEF files.
Package nef implements metadata extraction for Nikon NEF files.
orf
Package orf implements metadata extraction for Olympus ORF files.
Package orf implements metadata extraction for Olympus ORF files.
rw2
Package rw2 implements metadata extraction for Panasonic RW2 files.
Package rw2 implements metadata extraction for Panasonic RW2 files.
Package tiff implements extraction and injection of metadata within TIFF container files.
Package tiff implements extraction and injection of metadata within TIFF container files.
Package webp implements extraction and injection of EXIF and XMP metadata within WebP files.
Package webp implements extraction and injection of EXIF and XMP metadata within WebP files.

Jump to

Keyboard shortcuts

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