Documentation ¶
Overview ¶
Package exif implements an JPEG/Exif decoder and encoder.
Index ¶
- Constants
- Variables
- func Copy(w io.Writer, r io.Reader, x *Exif) error
- func IsFormat(err error) bool
- type Ascii
- type Byte
- type Entry
- type Exif
- func (x *Exif) DateTime() (t time.Time, ok bool)
- func (x *Exif) EncodeBytes() ([]byte, error)
- func (x *Exif) GPSInfo() (i GPSInfo, ok bool)
- func (x *Exif) LatLong() (lat, long float64, ok bool)
- func (x *Exif) Set(t uint32, v Value)
- func (x *Exif) SetDateTime(t time.Time)
- func (x *Exif) SetGPSInfo(i GPSInfo)
- func (x *Exif) SetLatLong(lat, long float64)
- func (x *Exif) SetThumbImage(im image.Image) error
- func (x *Exif) Tag(t uint32) *Tag
- func (x *Exif) ThumbImage() (image.Image, string, error)
- func (x *Exif) Time(timeTag, subSecTag uint32) (t time.Time, islocal, ok bool)
- type FormatError
- type Formatter
- type GPSInfo
- type Long
- type Rational
- type Short
- type Tag
- func (t *Tag) Ascii() (s string, ok bool)
- func (t *Tag) Byte() []byte
- func (t *Tag) IsType(typ uint16) bool
- func (t *Tag) Long() []uint32
- func (t *Tag) Rational() Rational
- func (t *Tag) SLong() []int32
- func (t *Tag) SRational() (numdenom []int32)
- func (t *Tag) Short() []uint16
- func (t *Tag) String() string
- func (t *Tag) Type() uint16
- func (t *Tag) Undef() []byte
- func (t *Tag) Valid() bool
- type Undef
- type Value
Constants ¶
const ( TypeByte = 1 // (unsigned) byte TypeAscii = 2 // ascii, zero-terminated TypeShort = 3 // unsigned 16-bit value TypeLong = 4 // unsigned 32-bit value TypeRational = 5 // two 32-bit values: numerator then denominator TypeUndef = 7 // raw bytes TypeSLong = 9 // signed long TypeSRational = 10 // signed rational // types from TIFF spec TypeSByte = 6 // signed byte TypeSShort = 8 // signed 16-bit value TypeFloat = 11 // 4-byte IEEE floating point value TypeDouble = 12 // 8-byte IEEE floating point value )
const TimeFormat = "2006:01:02 15:04:05"
Variables ¶
var ( // ErrCorruptHeader is returned if the Exif header is corrupt. ErrCorruptHeader = errors.New("exif: corrupt header") // ErrEmpty is returned when x.Encode is used with no exif data to encode. ErrEmpty = errors.New("exif: nothing to encode") // ErrTooLong is returned if the serialized exif is too long to be written in an Exif file. ErrTooLong = errors.New("exif: encoded length too long") )
var ( NotFound = errors.New("exif: exif data not found") ErrDecode = errors.New("exif: jpeg decode error") ErrEncode = errors.New("exif: jpeg encode error") )
var ( ErrMissingDir = errors.New("exif: missing IFD dir") ErrMissingTag = errors.New("exif: tag missing from dir") )
var ( ErrNoThumbnail = errors.New("exif: no thumbnail") ErrThumbnailTooBig = errors.New("exif: thumbnail too big") )
Functions ¶
Types ¶
type Entry ¶
type Entry struct { // Tag value (identifier). Tag uint16 // Entry data type. Type uint16 // Count is the number of values. Count uint32 // Value is the raw data encoded using the Exif.ByteOrder. Value []byte }
Entry is a tagged field within an Exif directory.
type Exif ¶
type Exif struct { // ByteOrder is the byte order used for decoding and encoding binary.ByteOrder // Main image TIFF metadata IFD0 []Entry // Main image sub-IFDs Exif, GPS, Interop []Entry // thumbnail IFD1 []Entry // Metadata Thumb []byte // Raw image data, typically JPEG }
Exif represents Exif format metadata in JPEG/Exif files.
func DecodeBytes ¶
DecodeBytes decodes the raw Exif data from p.
func (*Exif) DateTime ¶
DateTime reports the Exif datetime. The fields checked in order are Exif/DateTimeOriginal, Exif/DateTimeDigitized and Tiff/DateTime. If neither is available, ok == false is returned.
func (*Exif) EncodeBytes ¶
EncodeBytes encodes Exif data as a byte slice. It returns an error only if IFD0 is empty, the byte order is not set or the encoded length is too long for Exif.
To store the Exif within an image, use Copy instead.
func (*Exif) GPSInfo ¶
GPSInfo returns GPS data from x. It returns ok == true if least latitude and longitude values are present.
func (*Exif) Set ¶
Set sets the value of Exif tag t in x to v.
If v is nil, t is removed from x. Otherwise the Entry for t is created if it is not present in x.
Set panics is v is invalid (but not nil), or the value of (name & exiftag.DirMask) is not one of exiftag.{Tiff, Exif, GPS, Interop}.
func (*Exif) SetDateTime ¶
SetDateTime sets the fields Exif/DateTimeOriginal, Exif/DateTimeDigitized and Tiff/DateTime to t.
func (*Exif) SetGPSInfo ¶
SetGPSInfo sets the GPS data in x. If i.Version is nil, then Byte{2, 2, 0, 0} is used. If i.Alt.Valid is false or i.Time.IsZero() is true then the corresponding tags will be removed from x.
func (*Exif) SetLatLong ¶
SetLatLong sets GPS latitude and longitude in x.
func (*Exif) SetThumbImage ¶
SetThumbImage sets the thumbnail of x to im. It reports ErrThumbnailTooBig if the thumbnail is too large for use in Exif, and any errors encountered during encoding.
func (*Exif) Tag ¶
Tag returns the Tag t.
An invalid tag is returned if t is not present in x.
The value of (name & exiftag.DirMask) must be one of exiftag.{Tiff, Exif, GPS, Interop} otherwise Tag panics.
func (*Exif) ThumbImage ¶
ThumbImage returns the thumbnail image and its format. It reports ErrNoThumbnail if the thumbnail does not exist, or any other error encountered during decoding.
type FormatError ¶
type FormatError []string
FormatError holds warnings encountered by Decode or DecodeBytes if (part of) the Exif succesfully decoded but corrupt or invalid data were encountered.
Clients only interested only in reading the Exif may safely ignore a FormatError.
func (FormatError) Error ¶
func (e FormatError) Error() string
type GPSInfo ¶
type GPSInfo struct { // Version of the GPS IFD. Version []byte // Lat and Long are the GPS position in degrees. Lat, Long float64 // Alt is the altitude in meters above sea level. // Negative values mean altitude below sea level. Alt struct { Float64 float64 Valid bool } // Time specifies the time of the (last) GPS fix. Time time.Time }
GPSInfo represents GPS information within Exif.
type Rational ¶
type Rational []uint32
Rational is a Value of 32-bit unsigned numerator-denominator pairs, marshaled as TypeRational.
Rational is valid only if it is not empty and has an even number of elements.
func Sexagesimal ¶
Sexagesimal creates a sexagesimal triplet Rational with three components (hours/degrees, minutes and seconds) from v and res, where x = v/res means x seconds.
If res is zero, Sexagesimal panics. Res is used as the denominator of seconds. If res > 1e6, the denominator of seconds will be 1e6.
func (Rational) Sexagesimal ¶
Sexagesimal calculates the value of a r having hour (or degree), minute and second parts in 1/res second units, and can be used for GPSLatitude, GPSLongitude and GPSTimeStamp values.
The high value will be always zero if r represents hours/degrees less than or equal to 1e6, or res itself is less than or equal to 1e6.
type Short ¶
type Short []uint16
Short is a Value of 16-bit unsigned integers, marshaled as TypeShort.
type Tag ¶
type Tag struct { // ByteOrder to decode E.Value binary.ByteOrder // Entry for this Tag from Exif E Entry }
Tag represents a tagged field within Exif.
func (*Tag) Ascii ¶
Ascii returns the value of t as string. If t is invalid or is not TypeAscii, ok == false is returned.
func (*Tag) Byte ¶
Byte returns the value of t as a slice of bytes. If t is invalid or is not TypeByte, nil is returned.
func (*Tag) Long ¶
Long returns the value of t as an slice of unsigned 32-bit values. If t is invalid or is not TypeLong, nil is returned.
func (*Tag) Rational ¶
Rational returns the value of t as an slice of unsigned rational numerator/denominator values. If t is invalid or is not TypeRational, nil is returned.
func (*Tag) SLong ¶
SLong returns the value of t as an slice of signed 32-bit values. If t is invalid or is not TypeSLong, nil is returned.
func (*Tag) SRational ¶
SRational returns the value of t as an slice of signed rational numerator/denominator values. If t is invalid or is not TypeSRational, nil is returned.
func (*Tag) Short ¶
Short returns the value of t as a slice of unsigned 16-bit values. If t is invalid or is not TypeShort, nil is returned.