Reading and writing IPTC metadata on the command line using ExifTool

The tool that IPTC recommends the most for command-line use is Phil Harvey’s ExifTool (exiftool.org).

How you install the ExifTool software depends on your operating system and environment. Here are some installation instructions.

It has extensive documentation online. You can also run exiftool with no arguments for a complete list of available options with examples.

On this page:

Examples of reading IPTC metadata from the command line using exiftool

To get you started quickly, here are some examples of things that can be done with exiftool regarding IPTC metadata (we cover writing these fields below)

View all embedded metadata for an image file

Simply run exiftool with the file name / path to the image file that you wish to investigate:

exiftool <image file name>

This will simply display all metadata (IPTC, Exif and other formats) that can be extracted from the file.

View a single-valued metadata property in an image file

ExifTool can extract any single property from a media file. To find out which tag to use, first consult the IPTC Photo Metadata Standard Specification to get the XMP tag used, then consult the exiftool XMP tags page to determine how to specify that tag for exiftool.

Show only the Digital Source Type value

% exiftool -XMP-iptcExt:digitalsourcetype IPTC-PhotometadataRef-Std2021.1.jpg Digital Source Type : http://cv.iptc.org/newscodes/digitalsourcetype/softwareImage

Show only the Credit Line value

% exiftool -XMP-photoshop:Credit IPTC-PhotometadataRef-Std2021.1.jpg Credit : Credit Line (ref2021.1)

View multi-valued properties in image files

Here’s an example of viewing a non-structured but multi-valued property:

Show the creator value(s)

By default, exiftool shows multi-valued properties as comma-separated values on the same line:

Using the -struct option shows more clearly that it is in fact a list of values:

To make it totally clear that it is in fact a repeatable value, you can ask for JSON-encoded output:

And to ensure that the returned field names match those given in the input (e.g. “XMP-dc:creator” rather than just “Creator”), use the -G1 flag:

View a structured property for an image file

Some properties (such as Licensor which is used for Google’s Licensable feature) are structured, which means they contain sub-properties. In this case, running the simple exiftool -XMP-plus:Licensor test-image.jpg returns no results.

The secret is to use the -struct option:

View all properties read by Google Image Search for the Licensable badge feature

To read more than one property from a file, simply specify multiple ExifTool tags, each prefixed with a dash/hyphen character.

View all properties read by Google Image Search for Licensable badge and Synthetic Media features

View the full XMP data for an image file

This displays the internal structure of the XMP packet that is stored within an image file. This is usually only needed for debugging purposes or if you are curious about how XMP metadata is actually stored inside the file.

Examples of writing IPTC metadata on the command line using ExifTool

The same ExifTool XMP tags can be used to write metadata to image files on the command line.

Note that by default when writing to an image file using exiftool on the command line, the original unaltered version of the image is backed up as <filename>_original, for example test-image.jpg_original. This can be a life saver!

Writing Digital Source Type for synthetic media

Note that the value can be any text string, but we recommend using a full URI from the IPTC Digital Source Type vocabulary:

(Note that Google’s documentation on Digital Source Type for synthetic media specifies using only the ID, not the full URI. So if you are writing software to read these values, we recommend that you support both the fully-expanded URI and the short ID.)

Writing Creator and Credit Line metadata

The contents of these fields will be displayed in the Google Images search results details panel.

Writing Licensor URL metadata

This triggers the “Get this image on…” text in Google Images search results.

Note that this approach will not work if there are already two or more Licensor records in the image metadata. This is because the exiftool argument -XMP-plus:LicensorURL is a shortcut for “the LicensorURL sub-property in the first Licensor structure in the image.” But for most images, there will be only one licensor record or more likely no records at all, so this shortcut will work.

If you need to edit the LicensorURL of an image with two or more Licensor records, you should use the

Writing Web Statement of Rights metadata

This triggers the “Licensable” badge in Google image search results.

 

Appending to an existing set of repeatable tags

exiftool allows appending to a repeatable list of tags, for example Image Creator (dc:creator):

Do you have other questions? Would you like more examples? Have you spotted a problem? Just ask!

If you would like to see other exiftool examples, or if you have suggestions of exiftool incantations that you find useful and you would like to share them with others, please let us know!