Perl Script to extract metadata from images

Saturday, March 15, 2008

Its always been a headache to extract meta data from the image files like digital camera model, file extension, resolution etc. Here's the code that will help you do just that.

#!/usr/bin/perl
use strict;
use warnings;

my %good=(
'ColorSpace' => 1,
'ComponentsConfiguration' => 1,
'DateTime' => 1,
'DateTimeDigitized' => 1,
'DateTimeOriginal' => 1,
'ExifImageLength' => 1,
'ExifImageWidth' => 1,
'ExifVersion' => 1,
'FileSource' => 1,
'Flash' => 1,
'FlashPixVersion' => 1,
'ISOSpeedRatings' => 1,
'ImageDescription' => 1,
'InteroperabilityIndex' => 1,
'InteroperabilityVersion' => 1,
'JPEG_Type' => 1,
'LightSource' => 1,
'Make' => 1,
'MeteringMode' => 1,
'Model' => 1,
'Orientation' => 1,
'SamplesPerPixel' => 1,
'Software' => 1,
'YCbCrPositioning' => 1,
'color_type' => 1,
'file_ext' => 1,
'file_media_type' => 1,
'height' => 1,
'resolution' => 1,
'width' => 1
);

use Image::Info qw(image_info);


foreach my $cur_file (@ARGV) {
my $info = image_info($cur_file);
print "$cur_file ----------------------------------\n";
foreach my $key (sort keys %$info) {
if ($good{$key}) {
print " $key -> $info->{$key}\n";
}
}
}


-- Anish

0 comments:

  © Blogger templates Newspaper by Ourblogtemplates.com 2008

Back to TOP