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 ¶
- Constants
- func IsCriticalError(err error) bool
- func IsExifError(err error) bool
- func IsGPSError(err error) bool
- func IsInteroperabilityError(err error) bool
- func IsShortReadTagValueError(err error) bool
- func IsTagNotPresentError(err error) bool
- func RegisterParsers(ps ...Parser)
- type Exif
- func (x *Exif) DateTime() (time.Time, error)
- func (x *Exif) Get(name FieldName) (*tiff.Tag, error)
- func (x *Exif) JpegThumbnail() ([]byte, error)
- func (x *Exif) LatLong() (lat, long float64, err error)
- func (x *Exif) LoadTags(d *tiff.Dir, fieldMap map[uint16]FieldName, showMissing bool)
- func (x Exif) MarshalJSON() ([]byte, error)
- func (x *Exif) String() string
- func (x *Exif) Walk(w Walker) error
- type FieldName
- type Parser
- type TagNotPresentError
- type Walker
Examples ¶
Constants ¶
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
const ( ThumbJPEGInterchangeFormat = "ThumbJPEGInterchangeFormat" // offset to thumb jpeg SOI ThumbJPEGInterchangeFormatLength = "ThumbJPEGInterchangeFormatLength" // byte length of thumb )
thumbnail fields
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
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 ¶
IsCriticalError, given the error returned by Decode, reports whether the returned *Exif may contain usable information.
func IsExifError ¶
IsExifError reports whether the error happened while decoding the EXIF sub-IFD.
func IsGPSError ¶
IsGPSError reports whether the error happened while decoding the GPS sub-IFD.
func IsInteroperabilityError ¶
IsInteroperabilityError reports whether the error happened while decoding the Interoperability sub-IFD.
func IsShortReadTagValueError ¶
IsShortReadTagValueError identifies a ErrShortReadTagValue error.
func IsTagNotPresentError ¶
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 ¶
Exif provides access to decoded EXIF metadata fields and values.
func Decode ¶
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 ¶
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 ¶
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 ¶
JpegThumbnail returns the jpeg thumbnail if it exists. If it doesn't exist, TagNotPresentError will be returned
func (*Exif) LatLong ¶
LatLong returns the latitude and longitude of the photo and whether it was present.
func (*Exif) LoadTags ¶
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 ¶
MarshalJson implements the encoding/json.Marshaler interface providing output of all EXIF fields present (names and values).
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