Although some XMP metadata tags must be a string in a single language but some XMP metadata tags support “language alternative aka”lang-alt” values which allow values for multiple languages to be specified:
Iptc4xmpCore:AltTextAccessibility
dc:description
Iptc4xmpCore:ExtDescrAccessibility
dc:rights
dc:title
xmpRights:UsageTerms
as_lang_alt()
and set with the xmp()
object’s
set_item()
methodSee ?as_lang_alt
for more details but essentially create
a character vector or list and name the entries with an RFC 3066 name
tag.
library("xmpdf")
x <- xmp()
x$description <- "Description in only one default language"
x$title <- c(en = "An English Title",
fr = "Une titre française")
# XMP tags without an active binding must be manually coerced by `as_lang_alt`
transcript <- c(en = "An English Transcript",
fr = "Une transcription française") |>
as_lang_alt(default_lang = "en")
x$set_item("Iptc4xmpExt:Transcript", transcript)
Currently {xmpdf}
does not officially support entering
in “struct” XMP tags (although it does support “lang-alt” tags and
simple lists of basic XMP value types).
If necessary you’ll need to use an external program such as exiftool (perhaps via {exiftoolr}) to embed structured XMP tags.
{knitr}
supports the chunk option
fig.process
which accepts a function to post-process figure
files. The first argument should be a path to the figure file and may
optionally accept an options
argument which will receive a
list of chunk options. It should return a (possibly new) path to be
inserted in the output.
xmp()
objects have a fig_process()
method
which return a function that can be used for this
fig.process
option to embed XMP metadat into images.
Depending on the strings in its auto
argument this function
will also automatically map the following {knitr}
chunk
options to XMP tags:
fig.cap
to dc:description
fig.scap
to photoshop:Headline
fig.alt
to
Iptc4xmpCore:AltTextAccessibility
.. {r setup, echo=FALSE}
x <- xmpdf::xmp(creator = "John Doe",
date_created = "2023",
spdx_id = "CC-BY-4.0",
attribution_url = "https://example.com/attribution")
knitr::opts_chunk$set(fig.process = x$fig_process())
.. ..