xmp

package
v1.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func RegisterValueType(key string, typ ValueType)

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

func NewAlt(ns, prefix, name string, langValues ...[2]string) *Item

NewAlt creates an alternatives property. langValues is a sequence of [lang, value] pairs; use "x-default" as the lang for the canonical value.

func NewBag

func NewBag(ns, prefix, name string, values ...string) *Item

NewBag creates an unordered-set property.

func NewItem

func NewItem(ns, prefix, name, value string) *Item

NewItem creates a Simple property.

func NewItemLang

func NewItemLang(ns, prefix, name, lang, value string) *Item

NewItemLang creates a Simple property with an xml:lang qualifier.

func NewSeq

func NewSeq(ns, prefix, name string, values ...string) *Item

NewSeq creates an ordered-sequence property.

func NewStruct

func NewStruct(ns, prefix, name string, fields ...*Item) *Item

NewStruct creates a structured property with named fields.

func (*Item) Any

func (it *Item) Any() 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) AsBool

func (it *Item) AsBool() (bool, bool)

AsBool parses this Simple item as a boolean.

func (*Item) AsDuration

func (it *Item) AsDuration() (time.Duration, bool)

AsDuration parses this Simple item as a duration.

func (*Item) AsGPSCoord

func (it *Item) AsGPSCoord() (float64, bool)

AsGPSCoord parses this Simple item as a decimal degree coordinate.

func (*Item) AsRational

func (it *Item) AsRational() (rational.Rational, bool)

AsRational parses this Simple item as a rational value.

func (*Item) AsTime

func (it *Item) AsTime() (time.Time, bool)

AsTime parses this Simple item as a time value.

func (*Item) Bytes

func (it *Item) Bytes() []byte

Bytes returns nil — XMP properties are text-only (implements metadata.Metadata).

func (*Item) Image

func (it *Item) Image() image.Image

Image returns nil (implements metadata.Metadata).

func (*Item) ItemKind

func (it *Item) ItemKind() Kind

ItemKind returns the value kind.

func (*Item) Items

func (it *Item) Items() []*Item

Items returns child items: members of Bag/Seq/Alt, or fields of a Struct.

func (*Item) Key

func (it *Item) Key() string

Key returns the local property name, such as "title" (implements metadata.Metadata).

func (*Item) Lang

func (it *Item) Lang() string

Lang returns the xml:lang qualifier (non-empty for Simple items with a language tag and for Alt child items).

func (*Item) LocalName

func (it *Item) LocalName() string

LocalName returns the local property name.

func (*Item) MarshalJSON

func (it *Item) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Item) Metadata

func (it *Item) Metadata() metadata.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

func (it *Item) NS() string

NS returns the namespace prefix, such as "dc", or an empty string for an unqualified property (implements metadata.Metadata).

func (*Item) Name

func (it *Item) Name() string

Name returns "prefix:name", such as "dc:title", or just the name for an unqualified property.

func (*Item) Prefix

func (it *Item) Prefix() string

Prefix returns the preferred namespace prefix.

func (*Item) String

func (it *Item) String() string

String returns "key=value".

func (*Item) TypedValue

func (it *Item) TypedValue() any

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

func (it *Item) URI() string

URI returns the namespace URI, such as "http://purl.org/dc/elements/1.1/".

func (*Item) Value

func (it *Item) Value() string

Value returns the string value (implements metadata.Metadata). For Bag/Seq, values are joined with "; ". For Alt, the "x-default" value is returned, falling back to the first entry. For Struct, an empty string is returned.

func (*Item) ValueType

func (it *Item) ValueType() ValueType

ValueType returns the registered scalar type for this item's key.

type Kind

type Kind uint8

Kind describes the shape of an XMP property value.

const (
	Simple Kind = iota // a single string (optionally language-tagged)
	Bag                // unordered set of strings
	Seq                // ordered sequence of strings
	Alt                // localized alternatives keyed by xml:lang
	Struct             // nested record with named fields
)

func (Kind) String

func (k Kind) String() string

type Marshaler

type Marshaler interface {
	MarshalXMP(key string) map[string]string
}

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.

const (
	ValueTypeUnknown ValueType = iota
	ValueTypeTime
	ValueTypeDuration
	ValueTypeBoolean
	ValueTypeRational
	ValueTypeGPSCoord
)

func ValueTypeForKey

func ValueTypeForKey(key string) ValueType

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

func FromMetadata(items []metadata.Metadata, namespaces ...map[string]string) *XMP

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 New

func New() *XMP

New returns an empty XMP document.

func Parse

func Parse(data []byte) (*XMP, error)

Parse parses an XMP document from a byte slice.

func Read

func Read(r io.Reader) (*XMP, error)

Read parses an XMP document from r.

func (*XMP) About

func (x *XMP) About() string

About returns the resource the document describes, its rdf:about, which is usually empty, for the file the document is embedded in

func (*XMP) Add

func (x *XMP) Add(items ...*Item)

Add appends items to the document.

func (*XMP) Delete

func (x *XMP) Delete(key string) int

Delete removes all items matching key and returns the count removed.

func (*XMP) First

func (x *XMP) First(keys ...string) *Item

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

func (x *XMP) Get(key string) []*Item

Get returns all items whose key equals key. The key may be "prefix:name" or just the local name.

func (*XMP) Items

func (x *XMP) Items() []*Item

Items returns all top-level metadata properties.

func (*XMP) MarshalJSON

func (x *XMP) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*XMP) Metadata

func (x *XMP) Metadata() []metadata.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

func (x *XMP) SetAbout(about string)

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

func (*XMP) String

func (x *XMP) String() string

String returns the document encoded as an XMP/XML string.

func (*XMP) Write

func (x *XMP) Write(w io.Writer) error

Write encodes the XMP document as an XMP/RDF/XML packet to w, in the xpacket wrapper, to embed it in a file, such as a JPEG image.

func (*XMP) WriteSidecar

func (x *XMP) WriteSidecar(w io.Writer) error

WriteSidecar encodes the XMP document to w as a sidecar, a file of its own, such as photo.xmp, which starts with its x:xmpmeta element, without the xpacket wrapper.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL