All posts

Writing EXIF, IPTC and XMP metadata in Java and ColdFusion with PixyMeta

PixyMeta is a pure-Java library for writing EXIF, IPTC and XMP metadata, and we now maintain a fork of it. Here is why, what changed, and how to use it from Java, BoxLang and ColdFusion.

Reading image metadata from JPEG, TIFF and other formats with Java is a simple task. For many years there has been an excellent library for it: metadata-extractor. It is rock solid, has been ported to .NET and is used in many projects, such as Lucee and BoxLang. But it only reads. When it comes to writing EXIF, IPTC or XMP data, options are scarce. ExifTool is the de facto standard, but it is a Perl tool: you can shell out to it, but it is not native Java.

Common use cases for writing image metadata include stripping location data from images, and writing usage rights and creator information from digital asset management systems or stock photo libraries.

Until now there have been two notable open source options. Apache Commons Imaging has been in alpha since 2019, with only occasional updates. The second is PixyMeta by Wen Yu, who has since focused on iCafe, a larger library that also covers image manipulation, so PixyMeta has seen few updates as well. We built PixyMeta into our stock photo database solution more than five years ago, and since then it has processed tens of millions of images. Security issues, initially Log4j, led us to fork it, maintain it with regular updates and publish it on Maven Central.

What changed in our PixyMeta fork

The readers are now hardened against malformed and malicious files in every supported format. XMP parsing is protected against XML external entity attacks, and declared lengths, counts and offsets are checked before anything is allocated. A corrupt image either parses, has its damaged part skipped, or fails with an ordinary IOException. Before, it could crash the caller or eat all available memory.

Added WebP support for reading, writing and removing metadata, plus metadata removal for PNG and GIF. Maker notes from the major camera brands are decoded into named tags and survive an EXIF rewrite intact. If a format doesn't support an operation, the image passes through unchanged; previously you got an empty output file.

A new high-level editor reads an image's metadata, changes EXIF, IPTC, XMP, ICC profiles and comments by tag name and plain value, and writes the result back without touching the image data. Tag names work in any common spelling, including the ones ExifTool and metadata-extractor use. Dates, decimal GPS coordinates and fractions are converted to the right field type automatically, and several changes can go in one pass. IPTC text is now declared as UTF-8, so non-ASCII characters no longer show up garbled in other software.

The library still depends on nothing but the SLF4J API and runs on Java 11 and later, so it works from Lucee and BoxLang alike.

Install PixyMeta from Maven Central

The fork is on GitHub at akitogo/pixymeta and on Maven Central. Like the original, it is licensed under the Eclipse Public License 1.0 (EPL-1.0).

<dependency>
    <groupId>com.akitogo</groupId>
    <artifactId>pixymeta</artifactId>
    <version>1.4.0</version>
</dependency>

Java examples: add copyright, strip GPS data

Add copyright information to an image, in place:

Path file = Paths.get("photo.jpg");

MetadataEditor.read(file)
    .setExifTag("Copyright", "(c) 2026 Jane Doe")
    .setIptcTag("Copyright Notice", "(c) 2026 Jane Doe")
    .setIptcTag("By-line", "Jane Doe")
    .apply(file);

Strip the geo location but keep everything else:

MetadataEditor editor = MetadataEditor.read(file);
for (String tag : List.of("GPSLatitude", "GPSLatitudeRef", "GPSLongitude", "GPSLongitudeRef",
        "GPSAltitude", "GPSAltitudeRef", "GPSTimeStamp", "GPSDateStamp")) {
    editor.removeExifTag(tag);
}
editor.apply(file);

Or remove all metadata at once:

MetadataEditor.read(file).removeAll().apply(file);

BoxLang and CFML examples with bx-image

Since release 1.17 of bx-image, our PixyMeta fork brings metadata writing to BoxLang. ImageReadMetadata() returns a handle with chainable setters for EXIF, IPTC and XMP, and ImageStripMetadata() removes metadata from a file without re-encoding it. Because the image data is copied byte for byte, editing metadata is lossless and fast. bx-compat-cfml mirrors the tags to CFML, so existing ColdFusion code can use them too.

Add copyright information:

ImageReadMetadata( "photo.jpg" )
    .setExifTag( "Copyright", "(c) 2026 Jane Doe" )
    .setIPTCTag( "Copyright Notice", "(c) 2026 Jane Doe" )
    .setIPTCTag( "By-line", "Jane Doe" )
    .write();

Strip the geo location:

meta = ImageReadMetadata( "photo.jpg" );
for ( tag in [ "GPSLatitude", "GPSLatitudeRef", "GPSLongitude", "GPSLongitudeRef",
        "GPSAltitude", "GPSAltitudeRef", "GPSTimeStamp", "GPSDateStamp" ] ) {
    meta.removeExifTag( tag );
}
meta.write();

Or remove all metadata at once:

ImageStripMetadata( "photo.jpg" );