IMX is a pure Go library for extracting comprehensive metadata from image files. Zero external dependencies, production-ready, with extensive EXIF support (100+ tags).
- 🚀 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
go get github.com/gomantics/imxpackage 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)
}{
"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
}
}
}Run tests with:
go test ./...Run tests with coverage:
go test -cover ./...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.jpgThis library is provided as-is for use in your projects.
Contributions are welcome! Please ensure that:
- Code follows Go best practices
- Tests are included for new features
- Documentation is updated
The library works by:
- Reading the first few bytes of the file to detect the format via magic numbers
- Parsing format-specific headers and chunks to extract metadata
- Extracting EXIF data from JPEG APP1 segments or PNG eXIf chunks
- Detecting ICC profiles in format-specific locations
- Returning a comprehensive
ImageMetadatastruct with all extracted information
All format parsers are located in the formats/ subdirectory for better code organization.