exiv2

From LinuxReviews
Jump to navigationJump to search
Exiv2
Original author(s)Andreas Huggel
Developer(s)Andreas Huggel, Alan Pater, Dan Fandrich, Harry McKame, Ben Touchette, Adam Hooper, Thomas Beutlich, Wil Cowb and others
Repositorygithub.com/Exiv2/exiv2
Written inC++
Operating systemLinux, macoS
TypeImage metadata manipulation
License GPL v2
Websiteexiv2.org
Camera-icon.svg

exiv2 is a console image metadata viewer and editor capable of reading, writing and manipulating Exif, IPTC and XMP metadata. It supports all the common image formats such as jpeg, exv, cr2, crw, tiff, webm, png, bmp and many more. It is also available as a C++ library you can use to easily provide metadata-editing capabilities to any free software program. exiv2 is a great go-to Swiss army knife type tool for all image metadata manipulation.

Features[edit]

exiv2 is a Swiss army knife for photo metadata. It is capable of doing everything in that particular area. It is a command-line program, and it is, as such, not all that easy or strait-forward to use the more advanced editing capabilities. You will have to read or skim the somewhat long manual page if you want to utilize its full potential.

Just viewing a brief summery of what, if any, metadata is embedded into an image file is as easy as:

exiv2 filename.jpg

That command will show the file name, size MIME type, image resolution and, if present, some of the metadata included in filename.jpg.

exiv2 -pa filename.jpg will give you a list of all the metadata embedded in an image file. p is short for print and a tells the print feature to show all Exif, IPTC and XMP metadata.

Editing And Manipulating Photo Metadata[edit]

Using exiv2 to modify metadata is a bit harder. This can be done in two ways: You can either use exiv2 -M and provide a list commands, keys and values OR make a text file with the commands you would like to have applied to your image(s) and tell exiv2 about that file by running

exiv2 -m manipulation-commands.txt filename.jpg

Using a separate file is easier, specially if you want to add several typically the same keys to an image. You can combine -m and -M if you want to apply a series of metadata keys to all your images and add one or more per-image tags to each image.

Applying or changing a photo metadata key requires you to give one of the following commands:

command function
add add new metadata to an image (will not change keys if they exist)
set will either add metadata or change metadata if a key already exists
del removes a metadata key if one exists

add and del requires you to provide a key, preferably a value type and the actual value you would like to set. You do not have to provide the right kind of value type, exiv2 will try to figure out what to use if you do not provide one.

You will have to look up what key needs what value type in the schema that provides the key you want to use. As an example, the creator tag in the Dublin Core (dc) XMP schema should have the seq ProperName value type that is, by exiv2, called XmpSeq. Adding a creator tag to an image can be done by using these command-line parameters:

exiv2 -M"set Xmp.dc.creator XmpSeq LinuxReviews.org" filename.jpg

Using the -M option seems easy enough if you just want to add or change one tag. Changing more requires you to add multiple -M commands like:

exiv2 -M"set Xmp.dc.creator XmpSeq LinuxReviews.org" -M"set Xmp.xmpRights.UsageTerms LangAlt Public Domain filename.jpg

You can probably see how that becomes very cumbersome if you want to add or remove a lot of metadata tags.

Using A Command File To Manipulate Image Metadata[edit]

Gwenview showing metadata.jpg
the gwenview image viewer showing some photo metadata that has been added to it using exiv2.

Using a file to add a series of tags is preferable if you want to add tags images created by a program that won't let you edit them (like the GNU Image Manipulation Program) on a regular basis. Here is an example you can base your own command file on:

File: add-exif-copyright-info.txt
# MediaWiki shows this as "Copyright owner"
# exiftool calls it "Owner"
del  Xmp.xmpRights.Owner
set  Xmp.xmpRights.Owner         XmpBag  "LinuxReviews.org"

# Both MediaWiki and Exiftool calls this "Usage Terms"
set  Xmp.xmpRights.UsageTerms    LangAlt "Public Domain"

# URL to Copyright information
set  Xmp.xmpRights.WebStatement  XmpText "https://linuxreviews.org/LinuxReviews:Copyrights#Images"

# MediaWiki does not use this field
# exiftool calls it "Creator"
# Google images uses it as "Creator"
del  Xmp.dc.creator
set  Xmp.dc.creator              XmpSeq  "LinuxReviews.org"
#
# Defined as "Copyright Notice field"
# MediaWiki shows this as "Copyright holder" 
set  Xmp.dc.rights               LangAlt "(c) 2020 LinuxReviews.org - No rights reserved."

# Mediawiki shows this as "Credit/Provider"
# exiftool calls it "Credit"
set  Iptc.Application2.Credit    String "LinuxReviews.org"

# Both Mediawiki and exiftool calls htis "Source"
set  Iptc.Application2.Source    String "LinuxReviews.org"

# MediaWiki does not use this field.
# exiftool calls it Copyright Notice
set  Iptc.Application2.Copyright String "(c) 2020 LinuxReviews.org - No rights reserved."

set Exif.Image.Artist		"LinuxReviews.org"
set Exif.Photo.UserComment      Comment charset=Ascii Created by LinuxReviews.org

The above long lists of commands add some metadata that are useful both when uploading images to content management systems like MediaWiki, who do not strip them, and a limited number of search engines such as Google Image Search.

You can make exiv2 use the above command file by running

exiv2 -m /path/to/command-file.txt your_photo.jpg

You could, alternatively, place add-exif-copyright-info.txt in $HOME/bin and create a simple one-liner bash-script:

File: $HOME/bin/add-exif-copyright-info.sh
#!/bin/bash
exiv2 -m $HOME/bin/add-exif-copyright-info.txt "${*}"

Such a script would allow you to change metadata of an image to your standards by running

add-exif-copyright-info.sh file_name.jpg

You can combine -m command_file.txt with -M"add key value" if you want to add a series of standard commands and a key or two specific to the image you are working on.

Language-Specific Tags[edit]

exiv2 lets you set language-specific tags for any key using XMP LangAlt

Eradicating Metadata[edit]

Gwenview showing special facebook metadata.jpg
The gwenview photo viewer showing a photo of the k-pop group Rockit Girl with a "special" IPTC metadata tag that is added to all images uploaded to Facebook and other platforms they own such as Instagram. They use this key to track images hosted by their platforms that are re-used on and off their platforms.

Removing image metadata using exiv2 can be done by running a series of del commands listing individual keys you would like to remove. First, run exiv2 -pa file_name.jpg to see what keys are present and eradicate them with something like:

exiv2 -M"del Xmp.dc.rights" -M"del Exif.Image.Make" -M"del Exif.Image.Model"

Removing individual tags like that is obviously both foolish and very tiresome if you want to get rid of all the incriminating evidence berried within an images metadata. Luckily, there's a -d or --delete option available that allows you to quickly get rid of:

Valid exiv2 -d arguments
a all supported metadata (the default)
e Exif sectin
t Exif thumbnail only
i IPTC data
x XMP packet
c JPEG comment
C ICC Profile
I All IPTC data

The most useful of the --delete commands is probably a (you have to provide it even if it is the "default").

exiv2 -d a file_name.jpg

will eradicate all the metadata from file_name.jpg. Do note that this will not eradicate other information such as the sRGB profile information embedded into jpeg images. A file created by GIMP will still retain information like Profile Description: GIMP built-in sRGB and the same is true for pictures taken with some cameras.

Image File Formats Supported By Exiv2[edit]

Image Formats Supported By Exiv2
Type Exif IPTC XMP Image Comments ICC Profile
JPEG Read/Write Read/Write Read/Write Read/Write Read/Write
EXV Read/Write Read/Write Read/Write Read/Write Read/Write
CR2 Read/Write Read/Write Read/Write - Read/Write
CRW Read/Write - - Read/Write -
MRW Read Read Read - -
TIFF Read/Write Read/Write Read/Write - Read/Write
WEBP Read/Write - Read/Write - Read/Write
DNG Read/Write Read/Write Read/Write - Read/Write
NEF Read/Write Read/Write Read/Write - Read/Write
PEF Read/Write Read/Write Read/Write - Read/Write
ARW Read Read Read - -
RW2 Read Read Read - -
SR2 Read Read Read - -
SRW Read/Write Read/Write Read/Write - -
ORF Read/Write Read/Write Read/Write - -
PNG Read/Write Read/Write Read/Write Read/Write Read/Write
PGF Read/Write Read/Write Read/Write Read/Write Read/Write
RAF Read Read Read - -
EPS - - Read/Write - -
XMP - - Read/Write - -
GIF - - - - -
PSD Read/Write Read/Write Read/Write - -
TGA - - - - -
BMP - - - - -
JP2 Read/Write Read/Write Read/Write - Read/Write

Verdict And Conclusion[edit]

exiv2 is the best and most complete command-line tool for manipulating photo metadata. It is not all that easy to use if you don't know how but it is also not that hard to learn how to harness its power. You will hopefully have an idea how to use it after reading or skimming this page.

Alternatives[edit]

exiftool by Phil Harvey provides much of the same functionality. It is, like exiv2, a command-line tool. It's arguments are, like the exiftool.1 manual page shows, very differnet from exiv2.

Links[edit]

See also[edit]


Rate this article:
0.00
(0 votes)


Add your comment
LinuxReviews welcomes all comments. If you do not want to be anonymous, register or log in. It is free.