Skip to content

gomantics/imx

IMX - Image Metadata Extraction Library

Go Version License Go Report Card Coverage CI

IMX is a pure Go library for extracting comprehensive metadata from image files. Zero external dependencies, production-ready, with extensive EXIF support (100+ tags).

✨ Features

  • 🚀 Pure Go - No C dependencies, works anywhere Go works
  • 📸 Comprehensive EXIF - Extracts 130+ standard EXIF tags (TIFF, EXIF 2.3, GPS)
  • 🎯 Multiple Formats - JPEG, PNG, GIF, WebP, BMP
  • 🔒 Security Hardened - DoS protection, input validation, bounds checking
  • High Performance - Efficient parsing with minimal allocations
  • 🧪 Well Tested - 85.5% test coverage, 140+ test cases
  • 📦 Simple API - One function call to extract metadata
  • 🎨 Rich Metadata - Dimensions, color space, EXIF, ICC profiles, and more

📦 Installation

go get github.com/gomantics/imx

🚀 Quick Start

package main

import (
    "encoding/json"
    "fmt"
    "log"
    "github.com/gomantics/imx"
)

func main() {
    // Extract metadata from any supported image
    metadata, err := imx.MetadataFromFile("photo.jpg")
    if err != nil {
        log.Fatal(err)
    }

    // Access structured metadata
    fmt.Printf("Format: %s\n", metadata.File.FileType)
    fmt.Printf("Dimensions: %dx%d\n", metadata.Image.Width, metadata.Image.Height)
    fmt.Printf("Camera: %s %s\n", metadata.Camera.Make, metadata.Camera.Model)
    
    // Full metadata as JSON
    json.NewEncoder(os.Stdout).Encode(metadata)
}

Example Output

{
  "file": {
    "fileName": "photo.jpg",
    "fileSize": 17645657,
    "mimeType": "image/jpeg",
    "fileType": "JPEG"
  },
  "image": {
    "width": 4000,
    "height": 6000,
    "colorSpace": "RGB",
    "colorComponents": 3,
    "bitsPerSample": 8,
    "hasICCProfile": true
  },
  "camera": {
    "make": "NIKON CORPORATION",
    "model": "NIKON D3400",
    "lensModel": "70.0-300.0 mm f/4.5-6.3",
    "serialNumber": "8681363"
  },
  "exif": {
    "dateTimeOriginal": "2025:08:21 18:14:55",
    "exposureTime": "1/2000",
    "fNumber": 8,
    "iso": 800,
    "focalLength": 210,
    "meteringMode": "Pattern",
    "flash": "Flash did not fire",
    "rawTags": {
      "ApertureValue": 6,
      "ShutterSpeedValue": 10.97,
      "FocalPlaneXResolution": 2591.8
    }
  }
}

Testing

Run tests with:

go test ./...

Run tests with coverage:

go test -cover ./...

Examples

A runnable CLI example is provided under examples/print-metadata. It accepts a path to an image file and prints all metadata extracted by the imx library.

cd examples/print-metadata
go run . /path/to/image.jpg

License

This library is provided as-is for use in your projects.

Contributing

Contributions are welcome! Please ensure that:

  • Code follows Go best practices
  • Tests are included for new features
  • Documentation is updated

Implementation Details

The library works by:

  1. Reading the first few bytes of the file to detect the format via magic numbers
  2. Parsing format-specific headers and chunks to extract metadata
  3. Extracting EXIF data from JPEG APP1 segments or PNG eXIf chunks
  4. Detecting ICC profiles in format-specific locations
  5. Returning a comprehensive ImageMetadata struct with all extracted information

All format parsers are located in the formats/ subdirectory for better code organization.

About

A go package to extract image metadata

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •