Skip to content

Lightroom Classic color labels and XMP data in JPEGs

Recently I needed to add Lightroom Classic color labels to JPEGs using javascript in the browser. There exist some packages but I wasn't too happy with any of them, so I decided to write my own... of course.

From xmp-jpeg to the jpeg-xmp-writer package

Simon Boddy did a great job providing the most minimal solution that generates and writes XMP in a format that follows spec and is recognized by Lightroom Classic, exiftool and random online XMP/EXIF viewers (which probably also rely on exiftool).

However, the code does no longer work out of the box in the browser, so I updated it to work as a modern ES module, added easy access to the XMP DOM, made it work in node as well and wrote some documentation.

Here's the package "@mtillmann/jpeg-xmp-writer" and the github repository.

Writing Lightroom Classic Color Labels

To write color labels into your JPEG, use the library like this:

javascript
// import the writeXMP function
import { writeXMP } from '@mtillmann/jpeg-xmp-writer'

const arrayBuffer = /*...*/ // your JPEG file as an ArrayBuffer

// Write XMP metadata to the JPEG
const xmpArrayBuffer = writeXMP(arrayBuffer, {'xmp:Title': 'Hello, World!'})

// create a Blob from the arrayBuffer
const blob = new Blob([xmpedBuffer], { type: "image/jpeg" })

// create a URL for the Blob
const url = URL.createObjectURL(blob)

// create a link to download the JPEG
const a = document.createElement("a")
a.href = url
a.download = "test.jpg"
a.textContent = "Download"
document.body.appendChild(a)

// -> open the downloaded file in Lightroom Classic

Find more examples and how to work with Blobs and Data URLs in the README.

Color Label Pitfalls

The color label must match exactly what's set in your Lightroom Classic.

The color label is stored as a string in the XMP data, and Lightroom Classic will not recognize the color label if it's not an exact match. For example, if you call the red color label "to be deleted" in Lightroom Classic, you must also set it to "to be deleted" in the XMP data, or Lightroom Classic will not recognize it.

You cannot set the abstract value red in the XMP data.

This makes Color Labels very fragile, error-prone and not portable between different Lightroom Classic installations, depending on how the color labels are named.

This also affects different translations of Lightroom Classic, as the color labels are translated: By default the Purple color label is called Lila in german Lightroom Classic installations.


Clicking this button loads third-party content from utteranc.es and github.com