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 ¶
- Constants
- 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.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) Metadata() metadata.Metadata
- func (it *Item) NS() string
- func (it *Item) Name() string
- func (it *Item) Prefix() string
- func (it *Item) String() string
- func (it *Item) TypedValue() any
- func (it *Item) URI() string
- func (it *Item) Value() string
- func (it *Item) ValueType() ValueType
- type Kind
- type Marshaler
- type ValueType
- type XMP
- func (x *XMP) About() string
- func (x *XMP) Add(items ...*Item)
- func (x *XMP) Delete(key string) int
- func (x *XMP) First(keys ...string) *Item
- func (x *XMP) Get(key string) []*Item
- func (x *XMP) Items() []*Item
- func (x *XMP) MarshalJSON() ([]byte, error)
- func (x *XMP) Metadata() []metadata.Metadata
- func (x *XMP) SetAbout(about string)
- func (x *XMP) String() string
- func (x *XMP) Write(w io.Writer) error
- func (x *XMP) WriteSidecar(w io.Writer) error
Constants ¶
const Namespace = "xmp"
Namespace is the namespace of the properties of the XMP basic schema, such as xmp:CreateDate
Variables ¶
This section is empty.
Functions ¶
func RegisterValueType ¶
RegisterValueType registers or overrides the scalar type for a specific XMP key in "prefix:name" form, which the package of a schema calls for the properties of its schema, such as exif:FNumber.
Types ¶
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
Item represents a single XMP metadata property and implements metadata.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 metadata.Metadata):
- Simple → string
- Bag/Seq → []string
- Alt → map[string]string (lang → value)
- Struct → []*Item
func (*Item) AsDuration ¶
AsDuration parses this Simple item as a duration.
func (*Item) AsGPSCoord ¶
AsGPSCoord parses this Simple item as a decimal degree coordinate.
func (*Item) AsRational ¶
AsRational parses this Simple item as a rational value.
func (*Item) Bytes ¶
Bytes returns nil — XMP properties are text-only (implements metadata.Metadata).
func (*Item) Key ¶
Key returns the local property name, such as "title" (implements metadata.Metadata).
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) Metadata ¶
Metadata returns the property as metadata, in the namespace of its prefix, such as dc:title: a simple property as its typed value, such as a time for xmp:CreateDate, a localized property as its default text, and a list as its values, whose text is joined with "; ". It returns nil for a struct, or a property whose prefix or name isn't an identifier.
func (*Item) NS ¶
NS returns the namespace prefix, such as "dc", or an empty string for an unqualified property (implements metadata.Metadata).
func (*Item) Name ¶
Name returns "prefix:name", such as "dc:title", or just the name for an unqualified property.
func (*Item) TypedValue ¶
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).
func (*Item) URI ¶
URI returns the namespace URI, such as "http://purl.org/dc/elements/1.1/".
type Marshaler ¶
Marshaler is implemented by the value of metadata which is written to an XMP document as properties of its own, rather than as its text, such as a position, which is exif:GPSLatitude and exif:GPSLongitude. MarshalXMP returns the properties, by "prefix:name", and their values, for the metadata with the key, in "prefix:name" form, or none when the value is written as its text.
type ValueType ¶
type ValueType uint8
ValueType describes the scalar value type expected for an XMP tag.
func ValueTypeForKey ¶
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 ¶
FromMetadata creates an XMP document from a list of metadata entries. The namespace of an entry is its namespace prefix, and its key is its local name. Entries without a namespace are added as unqualified XMP properties. An entry whose value is a Marshaler is the properties it returns, rather than its text.
Optionally, callers can provide one namespace map of prefix -> URI to define extra namespaces (for example "audio" or "video").
func (*XMP) About ¶
About returns the resource the document describes, its rdf:about, which is usually empty, for the file the document is embedded in
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.
func (*XMP) Metadata ¶
Metadata returns the properties of the document as metadata, in the namespaces of their prefixes, such as dc:title (see Item.Metadata), and its xmpMM:DocumentID as dc:identifier too, when it doesn't have one, as it identifies the document, whichever version of it this is.
func (*XMP) SetAbout ¶
SetAbout sets the resource the document describes, its rdf:about, such as the path of a file, when the document isn't embedded in it