Exif Image Metadata with Perl

Exif information is a group of meta tags stored on an image. It can contain information about the image, the camera used to take it, software used to manipulate it, latitude and longitude, and even more. This example shows how to use Perl to extract and manipulate image exif data. You will first need to install the Image::ExifTool from CPAN

Basic Usage

use Image::ExifTool;

# Get Exif information from image file
my $exifTool = new Image::ExifTool;
my $sourceImageFileName = '123.jpg';
my $info = $exifTool->ImageInfo($sourceImageFileName);

# Print all key/value pairs
foreach (keys %$info) {
print "$_ => $$info{$_}\n";

Get Specific Tag Value

$value = $exifTool->GetValue('ImageSize');

Set New Tag value

$exifTool->SetNewValue('ImageHeight', '123');

Update Exif Information

# Overwrite same file
$success = $exifTool->WriteInfo($sourceImageFileName);

# Write to new file
$success = $exifTool->WriteInfo($sourceImageFileName, 'new.jpg');