How to use the command 'exiv2' (with examples)
The exiv2
command is an image metadata manipulation tool designed to handle the metadata of an image efficiently. This powerful command can read, write, modify, and delete metadata in formats such as Exif, IPTC, and XMP. Whether you are a photographer looking to manage the metadata associated with your image files or simply need to manipulate metadata for organization purposes, exiv2
is a versatile tool that can meet your needs.
Use case 1: Print a summary of the image Exif metadata
Code:
exiv2 path/to/file
Motivation:
Understanding the metadata of an image is essential for photographers and digital asset managers. Metadata provides crucial information about the conditions under which a photograph was taken, such as camera settings, date and time, and location. By using this command, you can quickly glean valuable insights and make informed decisions about how to manage your image library.
Explanation:
exiv2
: The base command invokes theexiv2
tool.path/to/file
: This is a placeholder that should be replaced with the actual path to the image file whose Exif metadata summary you wish to print.
Example Output:
File name : example.jpg
File size : 2345678 Bytes
MIME type : image/jpeg
Image size : 6000 x 4000
Camera make : Canon
Camera model : EOS 5D Mark IV
...
Use case 2: Print all metadata (Exif, IPTC, XMP) with interpreted values
Code:
exiv2 -P kt path/to/file
Motivation:
When managing image libraries, you may want a detailed look at all metadata types associated with an image, interpreted in a human-readable format. This command provides an expanded and comprehensive view of all the metadata categories, aiding in precise examination and workflow adjustments.
Explanation:
-P
: This flag stands forprint
, instructingexiv2
to display metadata.kt
: These options define the format for the output;k
stands for key andt
for the translated value.path/to/file
: Replace this with the actual file path to analyze metadata.
Example Output:
Exif.Image.DateTime Asci string 2019:09:28 10:11:22
Exif.Photo.ExposureTime Rational 1/250 sec
Iptc.Application2.Caption String A beautiful view of the mountains
Xmp.dc.subject XmpBag ["landscape", "nature"]
...
Use case 3: Print all metadata with raw values
Code:
exiv2 -P kv path/to/file
Motivation:
Sometimes the need arises to access metadata in its raw, uninterpreted state, especially when performing detailed analysis or debugging unexpected values. This command allows you to see the exact data stored within the image without formatting alterations, providing precision for in-depth examination.
Explanation:
-P
: The print command option for displaying metadata.kv
: This specifies to print keys and their corresponding raw values.path/to/file
: The file path where the target image is stored.
Example Output:
Exif.Image.DateTime A0000007:20190928T101122
Exif.Photo.ExposureTime 5/8
Iptc.Application2.Caption Photo_12345
...
Use case 4: Delete all metadata from an image
Code:
exiv2 -d a path/to/file
Motivation:
Privacy and file size are common concerns when sharing images. Removing all metadata can help protect personal data and reduce file size. Utilizing this command results in a clean image file free from potentially sensitive metadata, ensuring privacy and delivering a smaller file.
Explanation:
-d
: Signifies the delete operation.a
: Stands for ‘all’, meaning all metadata formats Exif, IPTC, and XMP will be erased.path/to/file
: Specify the image file from which you wish to remove metadata.
Example Output:
File "example.jpg" updated with no metadata.
Use case 5: Delete all metadata, preserving the file timestamp
Code:
exiv2 -d a -k path/to/file
Motivation:
Preserving the original file timestamp can be crucial when maintaining a chronological archive. This command is ideal when stripping metadata while wanting the file to retain its original creation or modification timestamp.
Explanation:
-d
: Initiates the delete command to remove metadata.a
: Targets all metadata types for deletion.-k
: Ensures the file timestamps are kept intact.path/to/file
: Path to the target image file.
Example Output:
File "example.jpg" updated with no metadata; original timestamps preserved.
Use case 6: Rename the file, prepending the date and time from metadata
Code:
exiv2 -r '%Y%m%d_%H%M%S_:basename:' path/to/file
Motivation:
Organizing files by date and time helps ensure a seamless workflow and easier retrieval when necessary. This command renames files using their metadata timestamps, facilitating better organization and archival efficiency.
Explanation:
-r
: Refers to the rename operation.'%Y%m%d_%H%M%S_:basename:'
: The pattern for renaming, which uses date and time formatted asYearMonthDay_HourMinuteSecond
.path/to/file
: The actual path where the image is stored.
Example Output:
File renamed to "20230928_101122_example.jpg".
Conclusion:
The exiv2
command is an invaluable tool for anyone needing to manage image metadata efficiently. By offering various functionalities from simple metadata printing to comprehensive data management including deletion and renaming, exiv2
ensures both precision and security in handling image data, making it a go-to choice for photographers, archivists, and enthusiasts alike.