imagemeta

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 29, 2022 License: MIT Imports: 11 Imported by: 0

README

Exif Tool

License Godoc ReportCard Coverage Status Build

Image Metadata (Exif and XMP) extraction for JPEG, HEIC, WebP, AVIF, TIFF and Camera Raw in golang. Focus is on providing wide variety of features while being perfomance oriented.

Documentation

See Documentation for more information.

Example Usage

Example usage:

package main

import (
	"flag"
	"fmt"
	"io"
	"os"

	"github.com/charCharacter/imagemeta"
	"github.com/charCharacter/imagemeta/exif"
	"github.com/charCharacter/imagemeta/meta"
	"github.com/charCharacter/imagemeta/xmp"
)

func main() {
	flag.Parse()
	if flag.NArg() != 1 {
		fmt.Fprintf(os.Stderr, "usage: main <file>\n")
		os.Exit(1)
	}
	f, err := os.Open(flag.Arg(0))
	if err != nil {
		fmt.Fatal(err)
	}
	defer func() {
		err = f.Close()
		if err != nil {
			panic(err)
		}
	}()

	m, err := imagemeta.Parse(f)
	if err != nil {
		panic(err)
	}
	fmt.Println(m.Exif())
	fmt.Println(m.Xmp())
	fmt.Println(m.ImageType())
	fmt.Println(m.Dimensions())
	fmt.Println(jpeg.DecodeConfig(m.PreviewImage()))

	e, _ := m.Exif()
	if e != nil {
		// ImageWidth and ImageHeight
		fmt.Println(e.Dimensions().Size())

		fmt.Println(e.Artist())
		fmt.Println(e.Copyright())

		fmt.Println(e.CameraMake())
		fmt.Println(e.CameraModel())
		fmt.Println(e.CameraSerial())

		fmt.Println(e.Orientation())

		fmt.Println(e.LensMake())
		fmt.Println(e.LensModel())
		fmt.Println(e.LensSerial())

		fmt.Println(e.ISOSpeed())
		fmt.Println(e.FocalLength())
		fmt.Println(e.LensModel())
		fmt.Println(e.Aperture())
		fmt.Println(e.ShutterSpeed())

		fmt.Println(e.Dimensions().Size())

		fmt.Println(e.Artist())
		fmt.Println(e.Copyright())

		fmt.Println(e.ISOSpeed())
		fmt.Println(e.FocalLength())
		fmt.Println(e.LensModel())
		fmt.Println(e.Aperture())
		fmt.Println(e.ShutterSpeed())

		fmt.Println(e.Aperture())
		fmt.Println(e.ExposureBias())

		fmt.Println(e.Artist())
		fmt.Println(e.Copyright())

		fmt.Println(e.CameraMake())
		fmt.Println(e.CameraModel())
		fmt.Println(e.CameraSerial())

		fmt.Println(e.LensMake())
		fmt.Println(e.LensModel())
		fmt.Println(e.LensSerial())

		// Example Tags
		fmt.Println(e.Dimensions())

		// Makernote Tags
		fmt.Println(e.CanonCameraSettings())
		fmt.Println(e.CanonFileInfo())
		fmt.Println(e.CanonShotInfo())
		fmt.Println(e.CanonAFInfo())

		// Time Tags
		fmt.Println(e.DateTime(time.Local))
		fmt.Println(e.ModifyDate(time.Local))
		fmt.Println(e.GPSDate(time.UTC))

		// GPS Tags
		fmt.Println(e.GPSCoords())
		fmt.Println(e.GPSAltitude())
		fmt.Println(e.GPSCoords())
		c, _ := e.GPSCellID()
		fmt.Println(c.ToToken())

		// Other Tags
		fmt.Println(e.ExposureProgram())
		fmt.Println(e.MeteringMode())
		fmt.Println(e.ShutterSpeed())
		fmt.Println(e.Aperture())
		fmt.Println(e.FocalLength())
		fmt.Println(e.FocalLengthIn35mmFilm())
		fmt.Println(e.ISOSpeed())
		fmt.Println(e.Flash())
		fmt.Println(e.ExposureValue())
		fmt.Println(e.ExposureBias())
	}
}

Imagehash

github.com/charCharacter/imagemeta/imagehash contains zero allocation Perceptual Hash algorithm called PHashFast. Based on https://github.com/corona10/goimagehash. Image will need to be resized to 64x64 prior to image hashing.

name                      old time/op    new time/op    delta
PHash/Regular-12           358µs ±26%     370µs ±17%  +3.28%  (p=0.000 n=189+179)
PHash/Fast-12             84.8µs ± 7%    84.8µs ± 7%    ~     (p=0.819 n=160+160)

name                      old alloc/op   new alloc/op   delta
PHash/Regular-12           193kB ± 0%     193kB ± 0%    ~     (p=0.683 n=198+196)
PHash/Fast-12              17.0B ± 0%     17.0B ± 0%    ~     (all equal)

name                      old allocs/op  new allocs/op  delta
PHash/Regular-12           4.68k ± 0%     4.68k ± 0%    ~     (all equal)
PHash/Fast-12               0.00           0.00         ~     (all equal)

Contributing

Suggestions and pull requests are welcome.

Benchmarks

This was benchmarked without the retrival of values. To run your own benchmarks see bench_test.go

BenchmarkImageMeta/.CR2/6D-12         			   80455	     20820 ns/op	   10218 B/op	      22 allocs/op
BenchmarkImageMeta/.CR2/7DMkII-12     	 		   75770	     17921 ns/op	   10219 B/op	      21 allocs/op
BenchmarkImageMeta/.CR2/CanonM6MkII-12         	   63640	     18128 ns/op	    9261 B/op	      21 allocs/op
BenchmarkImageMeta/.CR3/CanonR-12              	   72705	     16597 ns/op	    9236 B/op	      21 allocs/op
BenchmarkImageMeta/.CR3/CanonRP-12             	   59492	     17623 ns/op	    9216 B/op	      20 allocs/op
BenchmarkImageMeta/.CR3/CanonR3-12             	   57465	     20322 ns/op	   14632 B/op	      22 allocs/op
BenchmarkImageMeta/.CR3/CanonR5-12             	   55514	     19874 ns/op	   14632 B/op	      22 allocs/op
BenchmarkImageMeta/.CR3/CanonR6-12             	   76044	     16234 ns/op	    9234 B/op	      21 allocs/op
BenchmarkImageMeta/.HEIC/CanonR5-12            	   32150	     43434 ns/op	   10198 B/op	      21 allocs/op
BenchmarkImageMeta/.HEIC/CanonR6-12            	   34396	     37288 ns/op	   10196 B/op	      21 allocs/op
BenchmarkImageMeta/.JPG/GPS-12                 	  117636	      9807 ns/op	     280 B/op	       4 allocs/op
BenchmarkImageMeta/.JPG/GoPro6-12              	  154758	      6528 ns/op	     280 B/op	       4 allocs/op
BenchmarkImageMeta/.HEIC-12                    	    8442	    194884 ns/op	    4540 B/op	      15 allocs/op
BenchmarkImageMeta/.HEIC/iPhone11-12           	    6170	    185167 ns/op	    4569 B/op	      15 allocs/op
BenchmarkImageMeta/.HEIC/iPhone12-12           	   26725	     48433 ns/op	    1716 B/op	      11 allocs/op
BenchmarkImageMeta/.HEIC/iPhone13-12           	    6726	    152748 ns/op	    4561 B/op	      15 allocs/op
BenchmarkImageMeta/.NEF/Nikon-12               	   54534	     22582 ns/op	   10242 B/op	      23 allocs/op
BenchmarkImageMeta/.NEF/Nikon#01-12            	   53985	     23082 ns/op	   10244 B/op	      23 allocs/op
BenchmarkImageMeta/.RW2/Panasonic-12           	   52309	     20677 ns/op	    4555 B/op	      15 allocs/op
BenchmarkImageMeta/.ARW/Sony-12                	   99100	     11576 ns/op	    4769 B/op	      22 allocs/op
BenchmarkImageMeta/.WEBP/Webp-12               	 4978038	     285.9 ns/op	      24 B/op	       1 allocs/op
BenchmarkImageMeta/.DNG/Adobe-12               	   34141	     35345 ns/op	   20866 B/op	      30 allocs/op
BenchmarkImageMeta/.JPG/NoExif-12              	 1290793	     942.1 ns/op	     280 B/op	       4 allocs/op

Imagetype Identification

Images can be identified with: "github.com/charCharacter/imagemeta/imagetype" package.

Benchmarks can be found with the imagemeta/imagetype package

Example:

package main

import (
   "fmt"
   "os"

   "github.com/charCharacter/imagemeta/imagetype"
)

const imageFilename = "../../test/img/1.CR2"

func main() {
   var err error

   f, err := os.Open(imageFilename)
   if err != nil {
      panic(err)
   }
   defer f.Close()
   t, err := imagetype.Scan(f)
   if err != nil {
      panic(err)
   }
   fmt.Println(t)
}

TODO

  • Stabilize ImageTypes API
  • Add Exif parsing for individual image types (jpg, heic, cr2, tiff, dng)
  • Add XMP parsing as "xmp" package
  • Add Avif, Heic and CR3 image metadata support (riff format images)
  • Stabalize Imagemeta API
  • Improve test coverage
  • Create Thumbnail API
  • Add Webp image metadata support
  • Add Canon Exif Makernote support
  • Add Nikon Exif Makernote support
  • Add CRW image metadata support (ciff format images)
  • Documentation

Based on and Inspired by

Based on work by Dustin Oprea https://github.com/dsoprea/go-exif

Inspired by Phil Harvey http://exiftool.org

Some inspiration from RW Carlsen https://github.com/rwcarlsen/goexif

Special Thanks to:

Contributors

LICENSE

Copyright (c) 2020-2021, Evan Oberholster & Contributors

Copyright (c) 2019, Dustin Oprea

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

This section is empty.

Types

type ImageMeta

type ImageMeta interface {
	Dimensions() meta.Dimensions
	ImageType() imagetype.ImageType
	PreviewImage() io.Reader
	Exif() (exif.Exif, error)
	Xmp() (xmp.XMP, error)
}

ImageMeta interface for Image Metadata

func Parse

func Parse(r meta.Reader) (ImageMeta, error)

Parse meta.Reader for Image Metadata returns ImageMeta corresponding to identified image type.

type Metadata

type Metadata struct {
	*meta.Metadata
	// contains filtered or unexported fields
}

Metadata from an Image. The ExifDecodeFn and XmpDecodeFn are responsible for decoding their respective data.

func NewMetadata

func NewMetadata(r meta.Reader, xmpFn meta.DecodeFn, exifFn meta.DecodeFn) (m *Metadata, err error)

NewMetadata creates a new Metadata

Directories

Path Synopsis
Package bmff reads ISOBMFF boxes, as used by HEIF, AVIF, CR3, etc.
Package bmff reads ISOBMFF boxes, as used by HEIF, AVIF, CR3, etc.
Package cr3 decodes (CR3) Canon Raw 3 Metadata using the bmff package Based on: Laurent Clévy's work on Canon CR3 file structure found at (@Lorenzo2472) (https://github.com/lclevy/canon_cr3)
Package cr3 decodes (CR3) Canon Raw 3 Metadata using the bmff package Based on: Laurent Clévy's work on Canon CR3 file structure found at (@Lorenzo2472) (https://github.com/lclevy/canon_cr3)
Package exif provides functions for parsing and extracting Exif Information.
Package exif provides functions for parsing and extracting Exif Information.
ifds
Package ifds provides types and functions for decoding tiff Ifds
Package ifds provides types and functions for decoding tiff Ifds
ifds/exififd
Package exififd provides types for "RootIfd/ExifIfd"
Package exififd provides types for "RootIfd/ExifIfd"
ifds/gpsifd
Package gpsifd provides types for "RootIfd/GPSIfd"
Package gpsifd provides types for "RootIfd/GPSIfd"
ifds/mknote
Package mknote provides functions and types for decoding Exif Makernote values
Package mknote provides functions and types for decoding Exif Makernote values
tag
Package tag provides types and functions for decoding Exif Tags
Package tag provides types and functions for decoding Exif Tags
Package heic decodes Heic Metadata using the bmff package
Package heic decodes Heic Metadata using the bmff package
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
Package imagetype provides types and functions for identifying Image document types
Package imagetype provides types and functions for identifying Image document types
gen
Package jpeg reads metadata information (Exif and XMP) from a JPEG Image.
Package jpeg reads metadata information (Exif and XMP) from a JPEG Image.
Package meta contains meta types for image metadata
Package meta contains meta types for image metadata
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
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
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
cmd
xmpns
Package xmpns provides XMP Namespace information
Package xmpns provides XMP Namespace information

Jump to

Keyboard shortcuts

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