exif

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2015 License: AGPL-3.0, Apache-2.0 Imports: 13 Imported by: 0

README

To regenerate the regression test data, run go generate inside the exif package directory and commit the changes to regress_expected_test.go.

Documentation

Overview

Package exif implements decoding of EXIF data as defined in the EXIF 2.2 specification (http://www.exif.org/Exif2-2.PDF).

Index

Examples

Constants

View Source
const (
	ImageWidth                 FieldName = "ImageWidth"
	ImageLength                          = "ImageLength" // Image height called Length by EXIF spec
	BitsPerSample                        = "BitsPerSample"
	Compression                          = "Compression"
	PhotometricInterpretation            = "PhotometricInterpretation"
	Orientation                          = "Orientation"
	SamplesPerPixel                      = "SamplesPerPixel"
	PlanarConfiguration                  = "PlanarConfiguration"
	YCbCrSubSampling                     = "YCbCrSubSampling"
	YCbCrPositioning                     = "YCbCrPositioning"
	XResolution                          = "XResolution"
	YResolution                          = "YResolution"
	ResolutionUnit                       = "ResolutionUnit"
	DateTime                             = "DateTime"
	ImageDescription                     = "ImageDescription"
	Make                                 = "Make"
	Model                                = "Model"
	Software                             = "Software"
	Artist                               = "Artist"
	Copyright                            = "Copyright"
	ExifIFDPointer                       = "ExifIFDPointer"
	GPSInfoIFDPointer                    = "GPSInfoIFDPointer"
	InteroperabilityIFDPointer           = "InteroperabilityIFDPointer"
	ExifVersion                          = "ExifVersion"
	FlashpixVersion                      = "FlashpixVersion"
	ColorSpace                           = "ColorSpace"
	ComponentsConfiguration              = "ComponentsConfiguration"
	CompressedBitsPerPixel               = "CompressedBitsPerPixel"
	PixelXDimension                      = "PixelXDimension"
	PixelYDimension                      = "PixelYDimension"
	MakerNote                            = "MakerNote"
	UserComment                          = "UserComment"
	RelatedSoundFile                     = "RelatedSoundFile"
	DateTimeOriginal                     = "DateTimeOriginal"
	DateTimeDigitized                    = "DateTimeDigitized"
	SubSecTime                           = "SubSecTime"
	SubSecTimeOriginal                   = "SubSecTimeOriginal"
	SubSecTimeDigitized                  = "SubSecTimeDigitized"
	ImageUniqueID                        = "ImageUniqueID"
	ExposureTime                         = "ExposureTime"
	FNumber                              = "FNumber"
	ExposureProgram                      = "ExposureProgram"
	SpectralSensitivity                  = "SpectralSensitivity"
	ISOSpeedRatings                      = "ISOSpeedRatings"
	OECF                                 = "OECF"
	ShutterSpeedValue                    = "ShutterSpeedValue"
	ApertureValue                        = "ApertureValue"
	BrightnessValue                      = "BrightnessValue"
	ExposureBiasValue                    = "ExposureBiasValue"
	MaxApertureValue                     = "MaxApertureValue"
	SubjectDistance                      = "SubjectDistance"
	MeteringMode                         = "MeteringMode"
	LightSource                          = "LightSource"
	Flash                                = "Flash"
	FocalLength                          = "FocalLength"
	SubjectArea                          = "SubjectArea"
	FlashEnergy                          = "FlashEnergy"
	SpatialFrequencyResponse             = "SpatialFrequencyResponse"
	FocalPlaneXResolution                = "FocalPlaneXResolution"
	FocalPlaneYResolution                = "FocalPlaneYResolution"
	FocalPlaneResolutionUnit             = "FocalPlaneResolutionUnit"
	SubjectLocation                      = "SubjectLocation"
	ExposureIndex                        = "ExposureIndex"
	SensingMethod                        = "SensingMethod"
	FileSource                           = "FileSource"
	SceneType                            = "SceneType"
	CFAPattern                           = "CFAPattern"
	CustomRendered                       = "CustomRendered"
	ExposureMode                         = "ExposureMode"
	WhiteBalance                         = "WhiteBalance"
	DigitalZoomRatio                     = "DigitalZoomRatio"
	FocalLengthIn35mmFilm                = "FocalLengthIn35mmFilm"
	SceneCaptureType                     = "SceneCaptureType"
	GainControl                          = "GainControl"
	Contrast                             = "Contrast"
	Saturation                           = "Saturation"
	Sharpness                            = "Sharpness"
	DeviceSettingDescription             = "DeviceSettingDescription"
	SubjectDistanceRange                 = "SubjectDistanceRange"
	LensMake                             = "LensMake"
	LensModel                            = "LensModel"
)

Primary EXIF fields

View Source
const (
	ThumbJPEGInterchangeFormat       = "ThumbJPEGInterchangeFormat"       // offset to thumb jpeg SOI
	ThumbJPEGInterchangeFormatLength = "ThumbJPEGInterchangeFormatLength" // byte length of thumb
)

thumbnail fields

View Source
const (
	GPSVersionID        FieldName = "GPSVersionID"
	GPSLatitudeRef                = "GPSLatitudeRef"
	GPSLatitude                   = "GPSLatitude"
	GPSLongitudeRef               = "GPSLongitudeRef"
	GPSLongitude                  = "GPSLongitude"
	GPSAltitudeRef                = "GPSAltitudeRef"
	GPSAltitude                   = "GPSAltitude"
	GPSTimeStamp                  = "GPSTimeStamp"
	GPSSatelites                  = "GPSSatelites"
	GPSStatus                     = "GPSStatus"
	GPSMeasureMode                = "GPSMeasureMode"
	GPSDOP                        = "GPSDOP"
	GPSSpeedRef                   = "GPSSpeedRef"
	GPSSpeed                      = "GPSSpeed"
	GPSTrackRef                   = "GPSTrackRef"
	GPSTrack                      = "GPSTrack"
	GPSImgDirectionRef            = "GPSImgDirectionRef"
	GPSImgDirection               = "GPSImgDirection"
	GPSMapDatum                   = "GPSMapDatum"
	GPSDestLatitudeRef            = "GPSDestLatitudeRef"
	GPSDestLatitude               = "GPSDestLatitude"
	GPSDestLongitudeRef           = "GPSDestLongitudeRef"
	GPSDestLongitude              = "GPSDestLongitude"
	GPSDestBearingRef             = "GPSDestBearingRef"
	GPSDestBearing                = "GPSDestBearing"
	GPSDestDistanceRef            = "GPSDestDistanceRef"
	GPSDestDistance               = "GPSDestDistance"
	GPSProcessingMethod           = "GPSProcessingMethod"
	GPSAreaInformation            = "GPSAreaInformation"
	GPSDateStamp                  = "GPSDateStamp"
	GPSDifferential               = "GPSDifferential"
)

GPS fields

View Source
const UnknownPrefix = "UnknownTag_"

UnknownPrefix is used as the first part of field names for decoded tags for which there is no known/supported EXIF field.

Variables

This section is empty.

Functions

func IsCriticalError

func IsCriticalError(err error) bool

IsCriticalError, given the error returned by Decode, reports whether the returned *Exif may contain usable information.

func IsExifError

func IsExifError(err error) bool

IsExifError reports whether the error happened while decoding the EXIF sub-IFD.

func IsGPSError

func IsGPSError(err error) bool

IsGPSError reports whether the error happened while decoding the GPS sub-IFD.

func IsInteroperabilityError

func IsInteroperabilityError(err error) bool

IsInteroperabilityError reports whether the error happened while decoding the Interoperability sub-IFD.

func IsShortReadTagValueError

func IsShortReadTagValueError(err error) bool

IsShortReadTagValueError identifies a ErrShortReadTagValue error.

func IsTagNotPresentError

func IsTagNotPresentError(err error) bool

func RegisterParsers

func RegisterParsers(ps ...Parser)

RegisterParsers registers one or more parsers to be automatically called when decoding EXIF data via the Decode function.

Types

type Exif

type Exif struct {
	Tiff *tiff.Tiff

	Raw []byte
	// contains filtered or unexported fields
}

Exif provides access to decoded EXIF metadata fields and values.

func Decode

func Decode(r io.Reader) (*Exif, error)

Decode parses EXIF-encoded data from r and returns a queryable Exif object. After the exif data section is called and the tiff structure decoded, each registered parser is called (in order of registration). If one parser returns an error, decoding terminates and the remaining parsers are not called. The error can be inspected with functions such as IsCriticalError to determine whether the returned object might still be usable.

Example
package main

import (
	"fmt"
	"log"
	"os"

	"github.com/rwcarlsen/goexif/exif"
	"github.com/rwcarlsen/goexif/mknote"
)

func main() {
	fname := "sample1.jpg"

	f, err := os.Open(fname)
	if err != nil {
		log.Fatal(err)
	}

	// Optionally register camera makenote data parsing - currently Nikon and
	// Canon are supported.
	exif.RegisterParsers(mknote.All...)

	x, err := exif.Decode(f)
	if err != nil {
		log.Fatal(err)
	}

	camModel, _ := x.Get(exif.Model) // normally, don't ignore errors!
	fmt.Println(camModel.StringVal())

	focal, _ := x.Get(exif.FocalLength)
	numer, denom, _ := focal.Rat2(0) // retrieve first (only) rat. value
	fmt.Printf("%v/%v", numer, denom)

	// Two convenience functions exist for date/time taken and GPS coords:
	tm, _ := x.DateTime()
	fmt.Println("Taken: ", tm)

	lat, long, _ := x.LatLong()
	fmt.Println("lat, long: ", lat, ", ", long)
}
Output:

func (*Exif) DateTime

func (x *Exif) DateTime() (time.Time, error)

DateTime returns the EXIF's "DateTimeOriginal" field, which is the creation time of the photo. If not found, it tries the "DateTime" (which is meant as the modtime) instead. The error will be TagNotPresentErr if none of those tags were found, or a generic error if the tag value was not a string, or the error returned by time.Parse.

If the EXIF lacks timezone information or GPS time, the returned time's Location will be time.Local.

func (*Exif) Get

func (x *Exif) Get(name FieldName) (*tiff.Tag, error)

Get retrieves the EXIF tag for the given field name.

If the tag is not known or not present, an error is returned. If the tag name is known, the error will be a TagNotPresentError.

func (*Exif) JpegThumbnail

func (x *Exif) JpegThumbnail() ([]byte, error)

JpegThumbnail returns the jpeg thumbnail if it exists. If it doesn't exist, TagNotPresentError will be returned

func (*Exif) LatLong

func (x *Exif) LatLong() (lat, long float64, err error)

LatLong returns the latitude and longitude of the photo and whether it was present.

func (*Exif) LoadTags

func (x *Exif) LoadTags(d *tiff.Dir, fieldMap map[uint16]FieldName, showMissing bool)

LoadTags loads tags into the available fields from the tiff Directory using the given tagid-fieldname mapping. Used to load makernote and other meta-data. If showMissing is true, tags in d that are not in the fieldMap will be loaded with the FieldName UnknownPrefix followed by the tag ID (in hex format).

func (Exif) MarshalJSON

func (x Exif) MarshalJSON() ([]byte, error)

MarshalJson implements the encoding/json.Marshaler interface providing output of all EXIF fields present (names and values).

func (*Exif) String

func (x *Exif) String() string

String returns a pretty text representation of the decoded exif data.

func (*Exif) Walk

func (x *Exif) Walk(w Walker) error

Walk calls the Walk method of w with the name and tag for every non-nil EXIF field. If w aborts the walk with an error, that error is returned.

type FieldName

type FieldName string
const (
	InteroperabilityIndex FieldName = "InteroperabilityIndex"
)

interoperability fields

type Parser

type Parser interface {
	// Parse should read data from x and insert parsed fields into x via
	// LoadTags.
	Parse(x *Exif) error
}

Parser allows the registration of custom parsing and field loading in the Decode function.

type TagNotPresentError

type TagNotPresentError FieldName

A TagNotPresentError is returned when the requested field is not present in the EXIF.

func (TagNotPresentError) Error

func (tag TagNotPresentError) Error() string

type Walker

type Walker interface {
	// Walk is called for each non-nil EXIF field. Returning a non-nil
	// error aborts the walk/traversal.
	Walk(name FieldName, tag *tiff.Tag) error
}

Walker is the interface used to traverse all fields of an Exif object.

Jump to

Keyboard shortcuts

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