Documentation
¶
Overview ¶
Package xmp provides XMP (Extensible Metadata Platform) encoding and decoding. XMP stores structured metadata as RDF/XML, organized into namespaced properties that can be simple strings, ordered or unordered arrays, localized alternatives, or nested structures.
Index ¶
- func RegisterValueType(key string, typ ValueType)
- type Item
- func NewAlt(ns, prefix, name string, langValues ...[2]string) *Item
- func NewBag(ns, prefix, name string, values ...string) *Item
- func NewItem(ns, prefix, name, value string) *Item
- func NewItemLang(ns, prefix, name, lang, value string) *Item
- func NewSeq(ns, prefix, name string, values ...string) *Item
- func NewStruct(ns, prefix, name string, fields ...*Item) *Item
- func (it *Item) Any() any
- func (it *Item) AsBool() (bool, bool)
- func (it *Item) AsDuration() (time.Duration, bool)
- func (it *Item) AsGPSCoord() (float64, bool)
- func (it *Item) AsRational() (Rational, bool)
- func (it *Item) AsTime() (time.Time, bool)
- func (it *Item) Bytes() []byte
- func (it *Item) Image() image.Image
- func (it *Item) ItemKind() Kind
- func (it *Item) Items() []*Item
- func (it *Item) Key() string
- func (it *Item) Lang() string
- func (it *Item) LocalName() string
- func (it *Item) MarshalJSON() ([]byte, error)
- func (it *Item) NS() string
- func (it *Item) Prefix() string
- func (it *Item) String() string
- func (it *Item) TypedValue() any
- func (it *Item) Value() string
- func (it *Item) ValueType() ValueType
- type Kind
- type Rational
- type ValueType
- type XMP
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterValueType ¶ added in v1.9.0
RegisterValueType registers or overrides the scalar type for a specific XMP key in "prefix:name" form.
Types ¶
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
Item represents a single XMP metadata property and implements media.Metadata.
func NewAlt ¶
NewAlt creates an alternatives property. langValues is a sequence of [lang, value] pairs; use "x-default" as the lang for the canonical value.
func NewItemLang ¶
NewItemLang creates a Simple property with an xml:lang qualifier.
func (*Item) Any ¶
Any returns the property value as an appropriate Go type (implements media.Metadata):
- Simple → string
- Bag/Seq → []string
- Alt → map[string]string (lang → value)
- Struct → []*Item
func (*Item) AsDuration ¶ added in v1.9.0
AsDuration parses this Simple item as a duration.
func (*Item) AsGPSCoord ¶ added in v1.9.0
AsGPSCoord parses this Simple item as a decimal degree coordinate.
func (*Item) AsRational ¶ added in v1.9.0
AsRational parses this Simple item as a rational value.
func (*Item) Lang ¶
Lang returns the xml:lang qualifier (non-empty for Simple items with a language tag and for Alt child items).
func (*Item) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Item) TypedValue ¶ added in v1.9.0
TypedValue returns a typed scalar for Simple items where a registered type exists, and falls back to string (or the normal Any() for non-Simple kinds).
type Rational ¶ added in v1.9.0
Rational is a signed rational number represented as numerator/denominator.
type ValueType ¶ added in v1.9.0
type ValueType uint8
ValueType describes the scalar value type expected for an XMP tag.
func ValueTypeForKey ¶ added in v1.9.0
ValueTypeForKey returns the registered scalar type for key.
type XMP ¶
type XMP struct {
// contains filtered or unexported fields
}
XMP holds a parsed XMP metadata document.
func FromMetadata ¶ added in v1.9.0
FromMetadata creates an XMP document from a list of metadata entries. Keys in "prefix:name" form are split into namespace prefix and local name. Bare keys (without ':') are added as unqualified XMP properties.
Optionally, callers can provide one namespace map of prefix -> URI to define extra namespaces (for example "audio" or "video").
func (*XMP) First ¶
First returns the first item with a non-empty value from the first matching key in the ordered list. This implements the priority-fallback pattern used when the same semantic field can appear under multiple namespace prefixes, e.g. x.First("photoshop:DateCreated", "exif:DateTimeOriginal", "xmp:CreateDate").
func (*XMP) Get ¶
Get returns all items whose key equals key. The key may be "prefix:name" or just the local name.
func (*XMP) MarshalJSON ¶
MarshalJSON implements json.Marshaler.