Documentation
¶
Index ¶
- Constants
- Variables
- func IsInvalidFormat(err error) bool
- type DecodeResult
- type HandleTagFunc
- type ImageConfig
- type ImageFormat
- type InvalidFormatError
- type Options
- type Rat
- type Source
- type TagInfo
- type Tags
- func (t *Tags) Add(tag TagInfo)
- func (t Tags) All() map[string]TagInfo
- func (t *Tags) EXIF() map[string]TagInfo
- func (t Tags) GetDateTime() (time.Time, error)
- func (t Tags) GetLatLong() (lat float64, long float64, err error)
- func (t *Tags) Has(tag TagInfo) bool
- func (t *Tags) IPTC() map[string]TagInfo
- func (t *Tags) XMP() map[string]TagInfo
Constants ¶
const UnknownPrefix = "UnknownTag_"
UnknownPrefix is used as prefix for unknown tags.
Variables ¶
var ( // ErrStopWalking is a sentinel error to signal that the walk should stop. ErrStopWalking = fmt.Errorf("stop walking") )
Functions ¶
func IsInvalidFormat ¶
IsInvalidFormat reports whether the error was an InvalidFormatError.
Types ¶
type DecodeResult ¶ added in v0.13.0
type DecodeResult struct {
// ImageConfig contains basic image configuration.
// Note that this will be zero if the CONFIG source was not requested.
ImageConfig ImageConfig
}
DecodeResult contains the result of a Decode operation.
func Decode ¶
func Decode(opts Options) (result DecodeResult, err error)
Decode reads EXIF and IPTC metadata from r and returns a Meta struct.
type HandleTagFunc ¶
HandleTagFunc is the function that is called for each tag.
type ImageConfig ¶ added in v0.13.0
ImageConfig contains basic image configuration.
type ImageFormat ¶
type ImageFormat int
ImageFormat is the image format.
const ( // ImageFormatAuto signals that the image format should be detected automatically (not implemented yet). ImageFormatAuto ImageFormat = iota // JPEG is the JPEG image format. JPEG // TIFF is the TIFF image format. TIFF // PNG is the PNG image format. PNG // WebP is the WebP image format. WebP )
func (ImageFormat) String ¶
func (i ImageFormat) String() string
type InvalidFormatError ¶
type InvalidFormatError struct {
Err error
}
InvalidFormatError is used when the format is invalid.
func (*InvalidFormatError) Error ¶
func (e *InvalidFormatError) Error() string
func (*InvalidFormatError) Is ¶ added in v0.6.0
func (e *InvalidFormatError) Is(target error) bool
Is reports whether the target error is an InvalidFormatError.
type Options ¶
type Options struct {
// The Reader (typically a *os.File) to read image metadata from.
R io.ReadSeeker
// The image format in R.
ImageFormat ImageFormat
// If set, the decoder skip tags in which this function returns false.
// If not set, a default function is used that skips all EXIF tags except those in IFD0.
ShouldHandleTag func(tag TagInfo) bool
// The function to call for each tag.
HandleTag HandleTagFunc
// The default XMP handler is currently very simple:
// It decodes the RDF.Description.Attrs using Go's xml package and passes each tag to HandleTag.
// If HandleXMP is set, the decoder will call this function for each XMP packet instead.
// Note that r must be read completely.
HandleXMP func(r io.Reader) error
// If set, the decoder will only read the given tag sources.
// Note that this is a bitmask and you may send multiple sources at once.
Sources Source
// Warnf will be called for each warning.
Warnf func(string, ...any)
// Timeout is the maximum time the decoder will spend on reading metadata.
// Mostly useful for testing.
// If set to 0, the decoder will not time out.
Timeout time.Duration
// LimitNumTags is the maximum number of tags to read.
// Default value is 5000.
LimitNumTags uint32
// LimitTagSize is the maximum size in bytes of a tag value to read.
// Tag values larger than this will be skipped without notice.
// Note that this limit is not relevant for the XMP source.
// Default value is 10000.
LimitTagSize uint32
}
Options contains the options for the Decode function.
type Rat ¶
type Rat[T int32 | uint32] interface { Num() T Den() T Float64() float64 // String returns the string representation of the rational number. // If the denominator is 1, the string will be the numerator only. String() string }
Rat is a rational number.
type Source ¶ added in v0.5.0
type Source uint32
Source is a bitmask and you may send multiple sources at once.
const ( // EXIF is the EXIF tag source. EXIF Source = 1 << iota // IPTC is the IPTC tag source. IPTC // XMP is the XMP tag source. XMP // CONFIG source, which currently the image dimensions encoded in the image. // Note that this must not be confused with the dimensions stored in EXIF tags. CONFIG )
type TagInfo ¶
type TagInfo struct {
// The tag source.
Source Source
// The tag name.
Tag string
// The tag namespace.
// For EXIF, this is the path to the IFD, e.g. "IFD0/GPSInfoIFD"
// For XMP, this is the namespace, e.g. "http://ns.adobe.com/camera-raw-settings/1.0/"
// For IPTC, this is the record tag name as defined https://exiftool.org/TagNames/IPTC.html
Namespace string
// The tag value.
Value any
}
TagInfo contains information about a tag.
type Tags ¶
type Tags struct {
// contains filtered or unexported fields
}
Tags is a collection of tags grouped per source.
func (Tags) GetDateTime ¶
GetDateTime tries to find a date/time value from available metadata sources. It checks EXIF first (DateTimeOriginal, DateTime), then XMP (DateTimeOriginal, CreateDate, DateCreated), and finally IPTC (DateCreated + TimeCreated).
func (Tags) GetLatLong ¶
GetLatLong returns the latitude and longitude from available metadata sources. It checks EXIF first, then falls back to XMP.