Exiv2
Overview
Section titled “Overview”Exiv2 is a powerful C++ library and command-line utility for reading, writing, and manipulating image metadata including EXIF, IPTC, and XMP data. It supports all major image formats (JPEG, TIFF, PNG, RAW) and is essential for digital forensics, metadata analysis, and photography workflows. Exiv2 provides precise control over image metadata with batch processing capabilities.
Installation
Section titled “Installation”# Install on Debian/Ubuntu
sudo apt update
sudo apt install exiv2
# Install on macOS
brew install exiv2
# Install on Fedora/RHEL
sudo dnf install exiv2
# Build from source
git clone https://github.com/Exiv2/exiv2.git
cd exiv2
mkdir build && cd build
cmake ..
make
sudo make install
# Verify installation
exiv2 --version
Basic Metadata Viewing
Section titled “Basic Metadata Viewing”# Display all EXIF data for an image
exiv2 print image.jpg
# Show only specific EXIF tags
exiv2 -K Exif.Image.DateTime print image.jpg
# Extract EXIF and print to stdout
exiv2 -ex a image.jpg
# List file information
exiv2 -l image.jpg
# Verbose output with detailed information
exiv2 -v print image.jpg
Reading Metadata
Section titled “Reading Metadata”| Command | Purpose |
|---|---|
exiv2 print image.jpg | Display all metadata |
exiv2 -K DateTime print image.jpg | Show specific tag |
exiv2 -e a image.jpg | Extract all metadata |
exiv2 -e t image.jpg | Extract EXIF data |
exiv2 -e i image.jpg | Extract IPTC data |
exiv2 -e x image.jpg | Extract XMP data |
exiv2 -c txt print image.jpg | Output as text file |
exiv2 -c csv print image.jpg | Output as CSV |
Extracting Metadata to Files
Section titled “Extracting Metadata to Files”# Extract EXIF data to separate file
exiv2 -e a image.jpg
# Creates: image.exif (EXIF), image.iptc (IPTC), image.xmp (XMP)
# Extract as text format
exiv2 ex a image.jpg
# Creates: image.exif.txt
# Export specific metadata type
exiv2 -e t image.jpg # EXIF only
exiv2 -e i image.jpg # IPTC only
exiv2 -e x image.jpg # XMP only
# Save to custom filename
exiv2 -e a image.jpg
mv image.exif backup_metadata.exif
Modifying Metadata
Section titled “Modifying Metadata”# Set EXIF DateTime
exiv2 -M "set Exif.Image.DateTime 2024-05-01 14:30:00" image.jpg
# Set camera make and model
exiv2 -M "set Exif.Image.Make Canon" image.jpg
exiv2 -M "set Exif.Image.Model EOS\ 5D\ Mark\ IV" image.jpg
# Set GPS coordinates
exiv2 -M "set Exif.GPSInfo.GPSLatitude 40/1 42/1 45/1" image.jpg
exiv2 -M "set Exif.GPSInfo.GPSLongitude 74/1 0/1 36/1" image.jpg
# Add copyright information
exiv2 -M "set Exif.Image.Copyright My\ Company\ 2024" image.jpg
# Set software/processing info
exiv2 -M "set Exif.Image.Software Adobe\ Lightroom\ 7.0" image.jpg
Deleting Metadata
Section titled “Deleting Metadata”# Remove all EXIF data
exiv2 -d a image.jpg
# Delete specific EXIF tags
exiv2 -d EXIF image.jpg
# Remove IPTC data
exiv2 -d IPTC image.jpg
# Delete XMP data
exiv2 -d XMP image.jpg
# Remove GPS coordinates only
exiv2 -M "del Exif.GPSInfo.GPSLatitude" image.jpg
exiv2 -M "del Exif.GPSInfo.GPSLongitude" image.jpg
# Strip all metadata completely
exiv2 -d allExif -d allXmp -d allIptc image.jpg
Batch Operations
Section titled “Batch Operations”# Process multiple images in a directory
for file in *.jpg; do
exiv2 print "$file" > "${file%.jpg}.txt"
done
# Rename images based on EXIF DateTime
exiv2 -r '%Y%m%d_%H%M%S' *.jpg
# Copy metadata from one image to another
exiv2 -e a source.jpg
exiv2 -i a destination.jpg
# Remove metadata from all JPEGs
for file in *.jpg; do
exiv2 -d a "$file"
done
# Set same copyright on batch of images
for file in *.jpg; do
exiv2 -M "set Exif.Image.Copyright My\ Studio\ 2024" "$file"
done
Forensic Analysis
Section titled “Forensic Analysis”Extract comprehensive metadata for investigation:
# Full forensic metadata dump
exiv2 -Pgnycf image.jpg > forensic_report.txt
# Extract with all details
exiv2 print image.jpg | tee forensic_dump.txt
# Create timeline from image dates
exiv2 -K DateTime print *.jpg | sort -u
# Find all images modified on specific date
for file in *.jpg; do
DATE=$(exiv2 -K DateTime print "$file" | grep -o '2024-05-01')
if [ "$DATE" = "2024-05-01" ]; then
echo "$file"
fi
done
# Generate CSV report of all metadata
exiv2 -c csv print *.jpg > metadata_report.csv
Working with Different Formats
Section titled “Working with Different Formats”| Format | Support | Notes |
|---|---|---|
| JPEG | Full | Most common format |
| TIFF | Full | RAW images often stored as TIFF |
| PNG | Full | Supports EXIF in PNG |
| RAW | Partial | Canon, Nikon, Sony support varies |
| GIF | IPTC/XMP | No EXIF in GIF |
| WebP | Full | Modern format support |
| BMP | Limited | No EXIF support |
# Check supported formats
exiv2 -h 2>&1 | grep -A 20 "Supported formats"
# Extract metadata from RAW file
exiv2 print image.dng
# Work with TIFF metadata
exiv2 print image.tiff
Advanced Metadata Operations
Section titled “Advanced Metadata Operations”Copy Metadata Between Images
Section titled “Copy Metadata Between Images”# Extract from source
exiv2 -e a source.jpg
# Apply to destination
exiv2 -i a destination.jpg
# Or use insert mode (overwrites existing)
exiv2 -i a -o destination.jpg
Modify with Commands File
Section titled “Modify with Commands File”Create a batch commands file:
cat > metadata_changes.txt << 'EOF'
set Exif.Image.DateTime 2024-05-01 14:30:00
set Exif.Image.Copyright My Company 2024
set Exif.Image.Software Adobe Lightroom
del Exif.GPSInfo.GPSLatitude
del Exif.GPSInfo.GPSLongitude
EOF
# Apply all changes at once
exiv2 -M @metadata_changes.txt image.jpg
GPS Coordinate Formatting
Section titled “GPS Coordinate Formatting”GPS coordinates in EXIF use fractional degrees:
# Set GPS for New York City (40.7128°N, 74.0060°W)
# Format: degrees/1 minutes/1 seconds/1
exiv2 -M "set Exif.GPSInfo.GPSLatitude 40/1 42/1 45/1" image.jpg
exiv2 -M "set Exif.GPSInfo.GPSLatitudeRef N" image.jpg
exiv2 -M "set Exif.GPSInfo.GPSLongitude 74/1 0/1 36/1" image.jpg
exiv2 -M "set Exif.GPSInfo.GPSLongitudeRef W" image.jpg
Scripting Examples
Section titled “Scripting Examples”Mass Metadata Strip
Section titled “Mass Metadata Strip”#!/bin/bash
# Strip all metadata from images before upload
for file in "$@"; do
echo "Processing: $file"
exiv2 -d a "$file"
if [ $? -eq 0 ]; then
echo "✓ Metadata removed from $file"
else
echo "✗ Failed to process $file"
fi
done
Forensic Timeline Generator
Section titled “Forensic Timeline Generator”#!/bin/bash
# Create timeline of image capture
echo "Image,DateTaken,Camera,Lens,GPS"
for file in *.jpg; do
DATE=$(exiv2 -Pgt "$file" 2>/dev/null | grep DateTime)
CAMERA=$(exiv2 -Pgt "$file" 2>/dev/null | grep "Image Make")
echo "$file,$DATE,$CAMERA"
done > timeline.csv
Metadata Integrity Checker
Section titled “Metadata Integrity Checker”#!/bin/bash
# Verify metadata consistency
for file in *.jpg; do
EXIF=$(exiv2 -e a "$file" 2>&1 | grep -c "bytes written")
IPTC=$(exiv2 -e i "$file" 2>&1 | grep -c "bytes written")
XMP=$(exiv2 -e x "$file" 2>&1 | grep -c "bytes written")
echo "$file: EXIF=$EXIF, IPTC=$IPTC, XMP=$XMP"
done
Troubleshooting
Section titled “Troubleshooting”| Issue | Solution |
|---|---|
| ”Unsupported image type” | Check file format with file command |
| ”Cannot read metadata” | File may be corrupted, verify with ImageMagick |
| ”Permission denied” | Check file permissions with ls -la |
| GPS parsing errors | Verify GPS format (degrees/minutes/seconds) |
| Out of memory on large file | Split processing or use streaming |
Performance Optimization
Section titled “Performance Optimization”# Process large batches efficiently
time exiv2 -rc:1 print *.jpg > all_metadata.txt
# Parallel processing for multiple files
find . -name "*.jpg" -print0 | xargs -0 -P 4 exiv2 print
# Redirect to /dev/null to speed up directory scans
exiv2 -q print *.jpg > /dev/null
Privacy and Security
Section titled “Privacy and Security”# Audit image privacy before sharing
exiv2 print image.jpg | grep -i "gps\|copyright\|author"
# Remove sensitive metadata before upload
exiv2 -d a image.jpg
# Create privacy-safe copies
exiv2 -d a image.jpg -o clean_image.jpg
# Verify metadata was removed
exiv2 print clean_image.jpg
EXIF Tag Reference
Section titled “EXIF Tag Reference”| Category | Common Tags |
|---|---|
| Image Info | Make, Model, Orientation, DateTime |
| Camera Settings | ISO, Shutter, Aperture, FNumber |
| Lens | LensModel, FocalLength, FocalLengthIn35mm |
| GPS | GPSLatitude, GPSLongitude, GPSAltitude |
| Software | Software, ProcessingSoftware |
| Copyright | Copyright, Artist, ImageDescription |
Related Tools
Section titled “Related Tools”- ImageMagick — Image manipulation and conversion
- GraphicsMagick — Lightweight alternative to ImageMagick
- jhead — Lightweight JPEG/EXIF manipulation
- exiftool — Comprehensive metadata tool (Perl-based)
- ImageOptim — Batch EXIF removal tool
References
Section titled “References”- Exiv2 Official Documentation
- EXIF 2.32 Standard Specification
- IPTC Information Interchange Model
- XMP (Extensible Metadata Platform) Guide
- NIST Digital Forensics Tool Catalog