Help us shape the future of Go! Take the 2026 Go Developer Survey

imagemeta

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 14 Imported by: 16

README

imagemeta

License Go Reference Go Report Card Coverage Build

imagemeta is a high-performance Go library for extracting EXIF and XMP metadata from images and camera RAW formats.

It is built for:

  • ExifTool-aligned decoding behavior
  • low-allocation parsing on hot paths
  • broad support for modern and legacy camera formats
  • structured MakerNote decoding (Canon, Nikon, Sony, Panasonic, Apple)

Features

  • Decode EXIF from JPEG, TIFF, CR2, CR3, DNG, NEF, ARW, RW2, HEIC/HEIF/AVIF, PNG, and CRW
  • Parse XMP sidecars and embedded XMP blocks
  • Read Canon/Nikon/Sony/Panasonic/Apple MakerNotes
  • Extract embedded CR3 previews
  • Fast image type detection
  • Allocation-conscious perceptual image hashing (imagehash)

Install

go get github.com/evanoberholster/imagemeta

Supported Formats

  • JPEG: .jpg, .jpeg
  • TIFF + TIFF-based RAW: .tif, .tiff, .cr2, .dng, .nef, .arw, .rw2
  • ISO-BMFF family: .cr3, .heic, .heif, .avif
  • PNG (EXIF-in-TIFF payload)
  • CIFF/CRW: .crw

Quick Start

package main

import (
	"fmt"
	"os"

	"github.com/evanoberholster/imagemeta"
)

func main() {
	f, err := os.Open("image.jpg")
	if err != nil {
		panic(err)
	}
	defer f.Close()

	ex, err := imagemeta.Decode(f)
	if err != nil {
		panic(err)
	}

	fmt.Println("type:", ex.ImageType)
	fmt.Println("make:", ex.Make)
	fmt.Println("model:", ex.Model)
	fmt.Println("datetime:", ex.DateTimeOriginal)
}

Decode API

Top-level decode entry points:

  • Decode(io.ReadSeeker)
  • DecodeJPEG(io.ReadSeeker)
  • DecodeTiff(io.ReadSeeker)
  • DecodeCR3(io.ReadSeeker)
  • DecodeCRW(io.ReadSeeker)
  • DecodeHeif(io.ReadSeeker)
  • DecodePng(io.ReadSeeker)
  • PreviewCR3(io.ReadSeeker)

XMP Parsing

Parse a sidecar .xmp file:

x, err := xmp.ParseXmp(file)

Parse embedded XMP from an image:

x, err := xmp.Parse(file)

Package: github.com/evanoberholster/imagemeta/meta/xmp

Image Type Detection

Use imagetype for quick format detection before decode:

t, err := imagetype.Scan(r)

Package: github.com/evanoberholster/imagemeta/imagetype

Perceptual Hashing

imagehash provides 64-bit and 256-bit perceptual hashing with low-allocation paths.

Package: github.com/evanoberholster/imagemeta/imagehash

Performance Notes

  • Designed for low allocation and high throughput
  • Uses pooled readers and fixed-size parsing structures on hot paths
  • Suitable for large-batch metadata extraction pipelines

Benchmarks

  • General benchmarks: bench_test.go
Benchmark ns/op B/op allocs/op
Canon/CR2 6646 2440 20
Canon/CR3 8015 3723 22
Canon/JPG 2058 176 9
Nikon/JPG 1747 104 7
Nikon/NEF 10306 736 19
Sony/ARW 6584 1512 12

Note: benchmark results vary by CPU, Go version, and sample files.

TODO

  • Expand ExifTool parity coverage across MakerNote fields (Nikon, Sony, Panasonic, Apple, DJI)
  • Resolve known reverse-offset parsing edge case in MakerNote decoding
  • Improve malformed metadata resilience with more targeted fuzz and corpus tests
  • Add more specific benchmarks to compare edge cases
  • Document compatibility matrix by camera model/format

Contributing

Pull requests and issue reports are welcome.

Before opening a PR, run:

go test ./...
golangci-lint run

Acknowledgements

imagemeta is heavily inspired and tested on:

Additional references:

  • go4 (BMFF/HEIF parser concepts)
  • lclevy/canon_cr3
  • Lasse Heikkilä's HEIF thesis work
LLMs were used to assist in writing code, the code has been reviewed and has passed stringent checks.

License

MIT

Documentation

Overview

Package imagemeta provides functions for parsing and extracting Metadata from Images. Different image types such as JPEG, Camera Raw, DNG, TIFF, HEIF, and AVIF.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoExif               = meta.ErrNoExif
	ErrNoExifDecodeFn       = errors.New("error no Exif Decode Func set")
	ErrNoXmpDecodeFn        = errors.New("error no Xmp Decode Func set")
	ErrImageTypeNotFound    = imagetype.ErrImageTypeNotFound
	ErrMetadataNotSupported = errors.New("error metadata reading not supported for this imagetype")
)

Errors

Functions

func Decode added in v0.2.0

func Decode(r io.ReadSeeker) (exif.Exif, error)

func DecodeARW added in v1.0.0

func DecodeARW(r io.ReadSeeker) (exif.Exif, error)

DecodeARW decodes a Sony ARW file from an io.Reader returning Exif or an error.

func DecodeCR2 added in v0.2.0

func DecodeCR2(r io.ReadSeeker) (exif.Exif, error)

DecodeCR2 decodes a CR2 file from an io.Reader returning Exif or an error.

func DecodeCR3 added in v0.2.0

func DecodeCR3(r io.ReadSeeker) (exif.Exif, error)

DecodeCR3 decodes a CR3 file from an io.Reader returning Exif or an error.

func DecodeCRW added in v1.0.0

func DecodeCRW(r io.ReadSeeker) (exif.Exif, error)

DecodeCRW decodes a CRW file from an io.ReadSeeker returning Exif or an error.

func DecodeHeif added in v0.2.0

func DecodeHeif(r io.ReadSeeker) (exif.Exif, error)

DecodeHeif decodes a Heif file from an io.Reader returning Exif or an error. Needs improvement

func DecodeJPEG added in v0.2.0

func DecodeJPEG(r io.ReadSeeker) (exif.Exif, error)

DecodeJPEG decodes a JPEG file from an io.Reader returning Exif or an error.

func DecodePng added in v0.2.0

func DecodePng(r io.ReadSeeker) (exif.Exif, error)

DecodePng decodes a PNG file from an io.Reader returning Exif or an error.

func DecodeTiff added in v0.2.0

func DecodeTiff(r io.ReadSeeker) (exif.Exif, error)

DecodeTiff decodes a Tiff/DNG file from an io.Reader returning Exif or an error.

func PreviewCR3 added in v1.0.0

func PreviewCR3(r io.ReadSeeker) ([]byte, error)

PreviewCR3 previews a CR3 file from an io.Reader returning preview image binary or an error.

func SetLogger added in v0.2.0

func SetLogger(w io.Writer, level slog.Level)

Types

This section is empty.

Directories

Path Synopsis
Package imagehash processes a Perception hash and Average hash from an image.
Package imagehash processes a Perception hash and Average hash from an image.
transforms
Package transforms provides the transformations for imagehash
Package transforms provides the transformations for imagehash
transforms32
Package transforms32 contains DCT transformations
Package transforms32 contains DCT transformations
Package imagetype provides types and functions for identifying Image document types
Package imagetype provides types and functions for identifying Image document types
gen command
Package meta contains meta types for image metadata
Package meta contains meta types for image metadata
exif
Package tiff reads Tiff Header metadata information from image files before being processed by exif package
Package tiff reads Tiff Header metadata information from image files before being processed by exif package
exif/makernote
Package makernote defines maker-note tag IDs, camera-make identification, and the shared EXIF maker-note container for vendor-specific metadata.
Package makernote defines maker-note tag IDs, camera-make identification, and the shared EXIF maker-note container for vendor-specific metadata.
exif/makernote/canon
Package canon provides data types and functions for representing Canon Camera Makernote values
Package canon provides data types and functions for representing Canon Camera Makernote values
exif/makernote/nikon
Package nikon contains Nikon-specific metadata models shared by the EXIF decoder and downstream callers.
Package nikon contains Nikon-specific metadata models shared by the EXIF decoder and downstream callers.
exif/makernote/sony
Package sony provides data types and functions for representing Sony Camera Makernote values.
Package sony provides data types and functions for representing Sony Camera Makernote values.
jpeg
Package jpeg reads metadata information (Exif and XMP) from a JPEG Image.
Package jpeg reads metadata information (Exif and XMP) from a JPEG Image.
png
Package png reads PNG Header metadata information from image files before being processed by exif package
Package png reads PNG Header metadata information from image files before being processed by exif package
xmp
Package xmp provides functions for decoding .xmp sidecar files and XMP embedded within image files
Package xmp provides functions for decoding .xmp sidecar files and XMP embedded within image files
xmp/cmd command

Jump to

Keyboard shortcuts

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