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 ¶
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" )
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 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.
Example ¶
package main import ( "fmt" "log" "os" "github.com/rwcarlsen/goexif/exif" ) func main() { fname := "sample1.jpg" f, err := os.Open(fname) if err != nil { log.Fatal(err) } x, err := exif.Decode(f) if err != nil { log.Fatal(err) } camModel, _ := x.Get(exif.Model) date, _ := x.Get(exif.DateTimeOriginal) fmt.Println(camModel.StringVal()) fmt.Println(date.StringVal()) focal, _ := x.Get(exif.FocalLength) numer, denom := focal.Rat2(0) // retrieve first (only) rat. value fmt.Printf("%v/%v", numer, denom) }
Output:
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) 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