exiftool

package module
v0.0.0-...-223a900 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2020 License: MIT Imports: 17 Imported by: 0

README

Exif Tool

License Godoc ReportCard Coverage Status Build

This package provides for performance oriented decoding of exif and tiff encoded data.

Documentation

See Documentation for more information.

Example Usage

Example usage:

package main

import (
   "bytes"
   "fmt"
   "io/ioutil"
   "os"
   "time"

   "github.com/evanoberholster/exiftool"
)

const testFilename = "image.jpg"

func main() {
   var err error

   f, err := os.Open(testFilename)
   if err != nil {
      panic(err)
   }
   defer f.Close()

   start := time.Now()
   e, err := exiftool.ScanExif(f)
   if err != nil && err != exiftool.ErrNoExif {
      panic(err)
   }
   elapsed := time.Since(start)
   fmt.Println(elapsed)

   if err == exiftool.ErrNoExif {
      fmt.Println(e.XMLPacket())
      fmt.Println(e.Dimensions())
      return
   }

   // Strings
   fmt.Println(e.CameraMake())
   fmt.Println(e.CameraModel())
   fmt.Println(e.Artist())
   fmt.Println(e.Copyright())
   fmt.Println(e.LensMake())
   fmt.Println(e.LensModel())
   fmt.Println(e.CameraSerial())
   fmt.Println(e.LensSerial())
   //
   fmt.Println(e.Dimensions())
   fmt.Println(e.XMLPacket())
   //
   //// Makernotes
   fmt.Println(e.CanonCameraSettings())
   fmt.Println(e.CanonFileInfo())
   fmt.Println(e.CanonShotInfo())
   fmt.Println(e.CanonAFInfo())
   //
   //// Time
   fmt.Println(e.ModifyDate())
   fmt.Println(e.DateTime())
   fmt.Println(e.GPSTime())
   //
   //// GPS
   fmt.Println(e.GPSInfo())
   fmt.Println(e.GPSAltitude())
   //
   // Metadata
   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())

}

Contributing

Suggestions and pull requests are welcome.

Benchmarks

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

BenchmarkScanExif100/NoExif.jpg-8              1249808          996 ns/op       4496 B/op          5 allocs/op
BenchmarkScanExif100/350D.CR2-8                  39280        31519 ns/op      10445 B/op         46 allocs/op
BenchmarkScanExif100/XT1.CR2-8                   37731        31582 ns/op      10444 B/op         46 allocs/op
BenchmarkScanExif100/60D.CR2-8                   27439        43459 ns/op      12593 B/op         52 allocs/op
BenchmarkScanExif100/6D.CR2-8                    26264        45286 ns/op      13185 B/op         57 allocs/op
BenchmarkScanExif100/7D.CR2-8                    26625        46062 ns/op      13216 B/op         57 allocs/op
BenchmarkScanExif100/5DMKIII.CR2-8               24404        48578 ns/op      13212 B/op         57 allocs/op
BenchmarkScanExif100/1.CR3-8                    138854         8470 ns/op       5157 B/op         17 allocs/op
BenchmarkScanExif100/1.jpg-8                     52980        22424 ns/op      31394 B/op         32 allocs/op
BenchmarkScanExif100/1.NEF-8                     24420        50230 ns/op      13598 B/op         61 allocs/op
BenchmarkScanExif100/3.NEF-8                     20294        58299 ns/op      17008 B/op         67 allocs/op
BenchmarkScanExif100/1.ARW-8                     30277        39593 ns/op      11928 B/op         56 allocs/op
BenchmarkScanExif100/4.RW2-8                     34719        34740 ns/op       8202 B/op         31 allocs/op
BenchmarkScanExif100/hero6.gpr-8                 31630        38285 ns/op      13606 B/op         39 allocs/op

Imagetype Identification

Images can be identified with: "github.com/evanoberholster/exiftool/imagetype" package.

Benchmarks can be found with the exiftool/imagetype package

Example:

package main

import (
   "fmt"
   "os"

   "github.com/evanoberholster/exiftool/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

  • Update ImageTypes API
  • Write Exif extraction for individual image types (jpg, cr2, tiff)
  • Stabalize API
  • Write tests
  • Include support for CRW image type (ciff format images)
  • Create Thumbnail API
  • Documentation

Based on and Inspired by

Significantly 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

LICENSE

Copyright (c) 2020, Evan Oberholster & Contributors

Copyright (c) 2019, Dustin Oprea

Documentation

Overview

Package exiftool provides functions for scanning for Exif Information and extracting it

Index

Constants

This section is empty.

Variables

View Source
var (
	// Alias to meta Errors
	ErrInvalidHeader = meta.ErrInvalidHeader
	ErrNoExif        = meta.ErrNoExif
)

Errors

View Source
var (
	// ErrGpsCoordsNotValid means that some part of the geographic data were unparseable.
	ErrGpsCoordsNotValid = errors.New("error GPS coordinates not valid")
	// ErrGPSRationalNotValid means that the rawCoordinates were not long enough.
	ErrGPSRationalNotValid = errors.New("error GPS Coords requires a raw-coordinate with exactly three rationals")
)
View Source
var (
	// ErrDataLength is an error for data length
	ErrDataLength = errors.New("error the data is not long enough")

	// ErrIfdBufferLength
	ErrIfdBufferLength = errors.New("ifd buffer length insufficient")
)

Errors

View Source
var (
	ErrParseYear  = fmt.Errorf("error parsing Year")
	ErrParseMonth = fmt.Errorf("error parsing Month")
	ErrParseDay   = fmt.Errorf("error parsing Day")
	ErrParseHour  = fmt.Errorf("error parsing Hour")
	ErrParseMin   = fmt.Errorf("error parsing Min")
)

Errors for Parsing of Time

View Source
var (
	ErrEmptyTag = errors.New("error empty tag")
)

API Errors

Functions

This section is empty.

Types

type Exif

type Exif interface {
	// Aperture convenience func. "IFD/Exif" FNumber
	Aperture() (float32, error)

	// Artist convenience func. "IFD" Artist
	Artist() (artist string, err error)

	// CameraSerial convenience func. "IFD/Exif" BodySerialNumber
	CameraSerial() (serial string, err error)

	// CameraMake convenience func. "IFD" Make
	CameraMake() (make string)

	// CameraModel convenience func. "IFD" Model
	CameraModel() (model string)

	// Copyright convenience func. "IFD" Copyright
	Copyright() (copyright string, err error)

	// Dimensions convenience func. "IFD" Dimensions
	Dimensions() (width, height uint16, err error)

	// ExposureBias convenience func. "IFD/Exif" ExposureBiasValue
	ExposureBias() (string, error)

	// ExposureProgram convenience func. "IFD/Exif" ExposureProgram
	ExposureProgram() (ExposureMode, error)

	// Flash convenience func. "IFD/Exif" Flash
	Flash() (FlashMode, error)

	// FocalLength convenience func. "IFD/Exif" FocalLength
	// Lens Focal Length in mm
	FocalLength() (fl FocalLength, err error)

	// FocalLengthIn35mmFilm convenience func. "IFD/Exif" FocalLengthIn35mmFilm
	// Lens Focal Length Equivalent for 35mm sensor in mm
	FocalLengthIn35mmFilm() (fl FocalLength, err error)

	// ISOSpeed convenience func. "IFD/Exif" ISOSpeed
	ISOSpeed() (iso int, err error)

	// LensMake convenience func. "IFD/Exif" LensMake
	LensMake() (make string, err error)

	// LensModel convenience func. "IFD/Exif" LensModel
	LensModel() (model string, err error)

	// LensSerial convenience func. "IFD/Exif" LensSerialNumber
	LensSerial() (serial string, err error)

	// MeteringMode convenience func. "IFD/Exif" MeteringMode
	MeteringMode() (MeteringMode, error)

	// Orientation convenience func. "IFD" Orientation
	Orientation() (string, error)

	// ShutterSpeed convenience func. "IFD/Exif" ExposureTime
	ShutterSpeed() (ShutterSpeed, error)

	// XMLPacket convenience func. that returns XMP metadata
	// from a JPEG image or XMP Packet from "IFD" XMLPacket.
	// Whichever is present.
	XMLPacket() (str string, err error)
}

Exif is an interface representation of Exif Information

type ExifData

type ExifData struct {
	Make  string
	Model string
	XMP   string

	ImageType imagetype.ImageType
	// contains filtered or unexported fields
}

ExifData struct contains the parsed Exif information

func ParseExif

func ParseExif(r io.ReaderAt) (e *ExifData, err error)

ParseExif parses a tiff header from the io.ReaderAt and returns exif and an error. Sets exif imagetype as imageTypeUnknown

If the header is invalid ParseExif will return ErrInvalidHeader.

func ScanExif

func ScanExif(r io.ReaderAt) (e *ExifData, err error)

ScanExif identifies the imageType based on magic bytes and searches for exif headers, then it parses the io.ReaderAt for exif information and returns it. Sets exif imagetype from magicbytes, if not found sets imagetype to imagetypeUnknown.

If no exif information is found ScanExif will return ErrNoExif.

func (*ExifData) AddIfd

func (e *ExifData) AddIfd(ifd ifds.IFD)

AddIfd adds an Ifd to a TagMap

func (*ExifData) AddTag

func (e *ExifData) AddTag(ifd ifds.IFD, ifdIndex int, t tag.Tag)

AddTag adds a Tag to an Ifd -> IfdIndex -> tag.TagMap

func (*ExifData) Aperture

func (e *ExifData) Aperture() (float32, error)

Aperture convenience func. "IFD/Exif" FNumber

func (*ExifData) Artist

func (e *ExifData) Artist() (artist string, err error)

Artist convenience func. "IFD" Artist

func (*ExifData) CameraMake

func (e *ExifData) CameraMake() (make string)

CameraMake convenience func. "IFD" Make

func (*ExifData) CameraModel

func (e *ExifData) CameraModel() (model string)

CameraModel convenience func. "IFD" Model

func (*ExifData) CameraSerial

func (e *ExifData) CameraSerial() (serial string, err error)

CameraSerial convenience func. "IFD/Exif" BodySerialNumber

func (*ExifData) CanonAFInfo

func (e *ExifData) CanonAFInfo() (afInfo canon.AFInfo, err error)

CanonAFInfo - Canon Camera AutoFocus Information from the Makernote

func (*ExifData) CanonCameraSettings

func (e *ExifData) CanonCameraSettings() (canon.CameraSettings, error)

CanonCameraSettings convenience func. "IFD/Exif/Makernotes.Canon" CanonCameraSettings Canon Camera Settings from the Makernote

func (*ExifData) CanonFileInfo

func (e *ExifData) CanonFileInfo() (canon.FileInfo, error)

CanonFileInfo convenience func. "IFD/Exif/Makernotes.Canon" CanonFileInfo Canon Camera File Info from the Makernote

func (*ExifData) CanonShotInfo

func (e *ExifData) CanonShotInfo() (canon.ShotInfo, error)

CanonShotInfo convenience func. "IFD/Exif/Makernotes.Canon" CanonShotInfo Canon Camera Shot Info from the Makernote

func (*ExifData) Copyright

func (e *ExifData) Copyright() (copyright string, err error)

Copyright convenience func. "IFD" Copyright

func (*ExifData) DateTime

func (e *ExifData) DateTime() (time.Time, error)

DateTime - the date and time at which the EXIF file was created with sub-second precision

func (*ExifData) Dimensions

func (e *ExifData) Dimensions() (width, height uint16, err error)

Dimensions convenience func. "IFD" Dimensions

func (*ExifData) ExposureBias

func (e *ExifData) ExposureBias() (string, error)

ExposureBias convenience func. "IFD/Exif" ExposureBiasValue TODO: Add ExposureBias Function

func (*ExifData) ExposureProgram

func (e *ExifData) ExposureProgram() (ExposureMode, error)

ExposureProgram convenience func. "IFD/Exif" ExposureProgram

func (*ExifData) Flash

func (e *ExifData) Flash() (FlashMode, error)

Flash convenience func. "IFD/Exif" Flash

func (*ExifData) FocalLength

func (e *ExifData) FocalLength() (fl FocalLength, err error)

FocalLength convenience func. "IFD/Exif" FocalLength Lens Focal Length in mm

func (*ExifData) FocalLengthIn35mmFilm

func (e *ExifData) FocalLengthIn35mmFilm() (fl FocalLength, err error)

FocalLengthIn35mmFilm convenience func. "IFD/Exif" FocalLengthIn35mmFilm Lens Focal Length Equivalent for 35mm sensor in mm

func (*ExifData) GPSAltitude

func (e *ExifData) GPSAltitude() (alt float32, err error)

GPSAltitude convenience func. "IFD/GPS" GPSAltitude WIP

func (*ExifData) GPSCellID

func (e *ExifData) GPSCellID() (cellID s2.CellID, err error)

GPSCellID convenience func. retrieves "IFD/GPS" GPSLatitude and GPSLongitude converts them into an S2 CellID and returns the CellID.

If the CellID is not valid it returns ErrGpsCoordsNotValid.

func (*ExifData) GPSInfo

func (e *ExifData) GPSInfo() (lat, lng float64, err error)

GPSInfo convenience func. "IFD/GPS" GPSLatitude and GPSLongitude

func (*ExifData) GPSTime

func (e *ExifData) GPSTime() (timestamp time.Time, err error)

GPSTime convenience func. "IFD/GPS" GPSDateStamp and GPSTimeStamp

func (*ExifData) GetTag

func (e *ExifData) GetTag(ifd ifds.IFD, ifdIndex int, tagID tag.ID) (t tag.Tag, err error)

GetTag returns a tag from Exif and returns an error if tag doesn't exist

func (*ExifData) ISOSpeed

func (e *ExifData) ISOSpeed() (iso int, err error)

ISOSpeed convenience func. "IFD/Exif" ISOSpeed

func (*ExifData) LensMake

func (e *ExifData) LensMake() (make string, err error)

LensMake convenience func. "IFD/Exif" LensMake

func (*ExifData) LensModel

func (e *ExifData) LensModel() (model string, err error)

LensModel convenience func. "IFD/Exif" LensModel

func (*ExifData) LensSerial

func (e *ExifData) LensSerial() (serial string, err error)

LensSerial convenience func. "IFD/Exif" LensSerialNumber

func (*ExifData) MeteringMode

func (e *ExifData) MeteringMode() (MeteringMode, error)

MeteringMode convenience func. "IFD/Exif" MeteringMode

func (*ExifData) ModifyDate

func (e *ExifData) ModifyDate() (time.Time, error)

ModifyDate - the date and time at which the Exif file was modified

func (*ExifData) Orientation

func (e *ExifData) Orientation() (string, error)

Orientation convenience func. "IFD" Orientation TODO: Add Orientation Function

func (*ExifData) SetMetadata

func (e *ExifData) SetMetadata(m meta.Metadata)

SetMetadata sets the imagetype metadata in exif

func (*ExifData) ShutterSpeed

func (e *ExifData) ShutterSpeed() (ShutterSpeed, error)

ShutterSpeed convenience func. "IFD/Exif" ExposureTime

func (*ExifData) Thumbnail

func (e *ExifData) Thumbnail() (offset uint32, size uint32, err error)

Thumbnail convenience func.

func (*ExifData) XMLPacket

func (e *ExifData) XMLPacket() (str string, err error)

XMLPacket convenience func. that returns XMP metadata from a JPEG image or XMP Packet from "IFD" XMLPacket. Whichever is present.

type ExifReader

type ExifReader struct {
	// contains filtered or unexported fields
}

ExifReader -

func (*ExifReader) ByteOrder

func (er *ExifReader) ByteOrder() binary.ByteOrder

ByteOrder returns the ExifReader's byteOrder

func (*ExifReader) Read

func (er *ExifReader) Read(p []byte) (n int, err error)

Read reads from ExifReader and moves the placement marker

func (ExifReader) ReadAt

func (er ExifReader) ReadAt(p []byte, off int64) (n int, err error)

ReadAt reads from ExifReader at the given offset

func (*ExifReader) SetHeader

func (er *ExifReader) SetHeader(header meta.TiffHeader) error

SetHeader sets the ByteOrder, exifOffset and exifLength of an ExifReader from a TiffHeader and sets the ExifReader read offset to 0

type ExposureBias

type ExposureBias [2]int16

ExposureBias - [0] Numerator [1] Denominator

func (ExposureBias) MarshalJSON

func (eb ExposureBias) MarshalJSON() ([]byte, error)

MarshalJSON - Custom Marshall JSON

func (ExposureBias) String

func (eb ExposureBias) String() string

String - String value of Exposure Bias

type ExposureMode

type ExposureMode uint8

ExposureMode - Mode in which the Exposure was taken.

func (ExposureMode) String

func (em ExposureMode) String() string

String - Return Exposure Mode as a string

type FlashMode

type FlashMode uint8

FlashMode - Mode in which a Flash was used. (uint8) - value of FlashMode

func (FlashMode) Bool

func (fm FlashMode) Bool() bool

Bool - Returns true if Flash was fired

func (FlashMode) String

func (fm FlashMode) String() string

String - Return string for FlashMode

type FocalLength

type FocalLength float32

FocalLength - Focal Length in which the image was captured

func (FocalLength) String

func (fl FocalLength) String() string

type GpsInfo

type GpsInfo struct {
	Latitude, Longitude float64
	Altitude            int
	Timestamp           time.Time
}

GpsInfo encapsulates all of the geographic information in one place.

func (*GpsInfo) S2CellID

func (gi *GpsInfo) S2CellID() (cellID s2.CellID, err error)

S2CellID returns the cell-ID of the geographic location on the earth.

func (*GpsInfo) String

func (gi *GpsInfo) String() string

String returns a descriptive string.

type MeteringMode

type MeteringMode uint8

MeteringMode - Mode in which the image was metered.

func (MeteringMode) String

func (mm MeteringMode) String() string

String - Return Metering Mode as a string

MeteringMode values Derived from https://sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html (23/09/2019)

type ShutterSpeed

type ShutterSpeed [2]uint32

ShutterSpeed - [0] Numerator [1] Denominator

func (ShutterSpeed) MarshalJSON

func (ss ShutterSpeed) MarshalJSON() ([]byte, error)

MarshalJSON - Custom Marshall JSON

func (ShutterSpeed) String

func (ss ShutterSpeed) String() string

String - return a ShutterSpeed as a string

Directories

Path Synopsis
Package main provides an example command
Package main provides an example command
Package ifds provides types and functions for decoding tiff Ifds
Package ifds provides types and functions for decoding tiff Ifds
exififd
Package exififd provides types for "RootIfd/ExifIfd"
Package exififd provides types for "RootIfd/ExifIfd"
gpsifd
Package gpsifd provides types for "RootIfd/GPSIfd"
Package gpsifd provides types for "RootIfd/GPSIfd"
mknote
Package mknote provides functions and types for decoding Exif Makernote values
Package mknote provides functions and types for decoding Exif Makernote values
mknote/canon
Package canon provides functions for decoding of canon makernote values
Package canon provides functions for decoding of canon makernote values
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 provides a Metadata interface for interpreting metadata from different image types such as JPEG, TIFF, HEIF.
Package meta provides a Metadata interface for interpreting metadata from different image types such as JPEG, TIFF, HEIF.
cmd command
xmlmeta
Package xmlmeta provides types and functions for identifying and decoding image xml information as well as xmp files.
Package xmlmeta provides types and functions for identifying and decoding image xml information as well as xmp files.
Package tag provides types and functions for decoding Exif Tags
Package tag provides types and functions for decoding Exif Tags

Jump to

Keyboard shortcuts

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