Zum Inhalt springen

Exiv2

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.

# 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
# 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
CommandPurpose
exiv2 print image.jpgDisplay all metadata
exiv2 -K DateTime print image.jpgShow specific tag
exiv2 -e a image.jpgExtract all metadata
exiv2 -e t image.jpgExtract EXIF data
exiv2 -e i image.jpgExtract IPTC data
exiv2 -e x image.jpgExtract XMP data
exiv2 -c txt print image.jpgOutput as text file
exiv2 -c csv print image.jpgOutput as CSV
# 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
# 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
# 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
# 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

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
FormatSupportNotes
JPEGFullMost common format
TIFFFullRAW images often stored as TIFF
PNGFullSupports EXIF in PNG
RAWPartialCanon, Nikon, Sony support varies
GIFIPTC/XMPNo EXIF in GIF
WebPFullModern format support
BMPLimitedNo 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
# 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

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 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
#!/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
#!/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
#!/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
IssueSolution
”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 errorsVerify GPS format (degrees/minutes/seconds)
Out of memory on large fileSplit processing or use streaming
# 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
# 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
CategoryCommon Tags
Image InfoMake, Model, Orientation, DateTime
Camera SettingsISO, Shutter, Aperture, FNumber
LensLensModel, FocalLength, FocalLengthIn35mm
GPSGPSLatitude, GPSLongitude, GPSAltitude
SoftwareSoftware, ProcessingSoftware
CopyrightCopyright, Artist, ImageDescription
  • 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
  • Exiv2 Official Documentation
  • EXIF 2.32 Standard Specification
  • IPTC Information Interchange Model
  • XMP (Extensible Metadata Platform) Guide
  • NIST Digital Forensics Tool Catalog