Documentation
¶
Overview ¶
Package xmp performs field-level surgery on the XMP packet carried in a JPEG APP1 segment. It operates on the segment payload (the bytes beginning with the Adobe xap namespace signature) and does not import the jpeg package, so it stays independently usable and testable.
Editing is length-preserving: Clean rewrites target field values in place via targeted regexp replacement, then expands the xpacket whitespace padding so the payload keeps its original byte length. Preserving length means none of the surrounding JPEG/TIFF offsets need to move.
Adobe writes the xmpMM:History stEvt:softwareAgent in ATTRIBUTE form (<rdf:li stEvt:softwareAgent="..."/>), not only element form; Parse and Clean handle both. Missing the attribute form silently skipped every real Lightroom/Photoshop file, so patchAll covers both forms deliberately.
Lifted from codeberg.org/elkarrde/tidy-exif.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clean ¶
Clean empties or replaces the target fields in a raw XMP payload in place, preserving the payload's byte length via xpacket whitespace padding.
replacements maps field names ("CreatorTool", "MetadataDate", "DocumentID", "InstanceID", "OriginalDocumentID", "SoftwareAgent") to replacement values; any field absent from the map is emptied. All history entries are replaced with the single "SoftwareAgent" value.
If the payload carries no Adobe data, Clean returns the original payload unchanged with changed == false.
func CleanLocation ¶ added in v0.2.0
CleanLocation blanks the value of every location and GPS field in a raw XMP APP1 payload, preserving the payload's byte length via xpacket whitespace padding (the same length-preserving technique as Clean). It is a distinct, opt-in entry point: the default Clean targets only Adobe-signature fields and is consumed by tidy-exif, so folding location handling into it would silently change that behavior.
Both attribute form (name="value") and element form (<name>value</name>) are blanked, at every nesting depth, so location data inside the structured Iptc4xmpExt:LocationCreated / LocationShown containers is emptied along with the flat fields. The empty containers are left in place; they carry no data.
If the payload holds no location data (nothing changes), CleanLocation returns the original payload unchanged with changed == false.
func ReadProperties ¶ added in v0.3.1
ReadProperties extracts the requested simple (scalar) XMP properties from a raw XMP APP1 payload, matching each by namespace URI and local name. Both forms real writers use are recognised: attribute form (ns:Name="value", how AnalogExif/aux write their scalars on rdf:Description) and simple element form (<ns:Name>value</ns:Name>). XML entities are decoded by the token reader. The first occurrence of a property wins; properties absent or empty are omitted.
This is a read-only primitive with no vocabulary of its own — the caller names the namespaces and fields it wants (e.g. the AnalogExif film schema, or aux:Lens) and policy stays in the caller. Results are keyed by the same Property values passed in. The payload must begin with the Adobe xap namespace signature (as jpeg.Segment.Data for an XMP segment does).
Parsing is best-effort: the error result is non-nil only when the payload lacks the XMP signature. A malformed or truncated packet is not reported as an error — whatever was collected before the fault is returned, so an absent property and a parse failure are indistinguishable from the result alone.
Types ¶
type Fields ¶
type Fields struct {
CreatorTool string
MetadataDate string
DocumentID string
InstanceID string
OriginalDocumentID string
SoftwareAgents []string // one entry per xmpMM:History item
}
Fields holds the Adobe-specific XMP metadata targeted for removal or replacement.
func Parse ¶
Parse extracts the target fields from a raw XMP APP1 payload using an encoding/xml token decoder. The payload must begin with the Adobe xap namespace signature. Both attribute and element forms of each field are handled, including the attribute-form history entries that Lightroom and Photoshop actually write.
type Property ¶ added in v0.3.1
type Property struct {
Namespace string // namespace URI, e.g. "http://analogexif.sourceforge.net/ns/"
Name string // local name, e.g. "Film"
}
Property identifies an XMP property by its namespace URI and local name, independent of the namespace prefix a given file happens to bind (one file may write "AnalogExif:Film", another a different prefix for the same URI; the URI is the stable identifier).