Monday 16 November 2009

Updating Metadata of Image file using Perl script !


Exiv2 is a C++ library and a command line utility to manage image metadata. It provides fast and easy read and write access to the Exif, IPTC and XMP metadata of images in various formats. Exiv2 is available as free software and with a commercial license, and is used in many projects.

The Exiv2 library provides
  • fast read and write access to the Exif, IPTC, and XMP metadata of an image
  • an easy to use and extensively documented API
  • a smart IPTC implementation that does not affect data that programs like Photoshop store in the same image segment
  • adjust the Exif timestamp (that's how it all started...)
  • rename Exif image files according to the Exif timestamp
  • extract, insert and delete Exif, IPTC and XMP metadata and JPEG comments
  • extract previews from RAW images and thumbnails from the Exif metadata
  • insert and delete the thumbnail image embedded in the Exif metadata
  • print, set and delete the JPEG comment of JPEG images
  • fix the Exif ISO setting of picture taken with Canon and Nikon cameras

By default, the utility can print a summary of the Exif information by using the following command.

$ exiv2 image1.jpg

With the -pt option, the utility prints out all Exif information as interpreted (translated) values. Alternatively, -pv prints the plain Exif data values.

$ exiv2 -pt image1.jpg

A short description of the actions and options supported by the Exiv2 utility can be viewed by

$ exiv2 -h


Now to write a perl program to modify the metadata of an image you are interested in Ubuntu

Step - 1
*********
Include the EXIF/IPTC metadata manipulation library

$ sudo apt-get install eviv2 libexiv2-5 libexiv2-7 libexiv2-dev libexiv2-7-dev

Step - 2
********

Try the perl program given below:

#!/usr/bin/perl
use warnings;
use POSIX;
use Image::ExifTool qw(:Public);
my $jpg = $ARGV[0] or die "Usage: $0 ";
my $tool = Image::ExifTool->new();
$tool->ExtractInfo($jpg);
$tool->SetNewValue('Make'); # Deleting this tag magically makes it work
$now_time = strftime "%Y:%m:%d %H:%M:%S", localtime;
$success = $tool->SetNewValue("DateTimeOriginal",$now_time);
if ($success) {
$success = $tool->WriteInfo($jpg);
print "DateTimeOriginal Update failed", $tool->GetValue('Error'), "\n" if ! $success;
}
$success = $tool->SetNewValue("DateTime",$now_time);
if ($success) {
$success = $tool->WriteInfo($jpg);
print "DateTime Update failed", $tool->GetValue('Error'), "\n" if ! $success;
}
$success = $tool->SetNewValue("DateTimeDigitized",$now_time);
if ($success) {
$success = $tool->WriteInfo($jpg);
print "DateTimeDigitized Update failed", $tool->GetValue('Error'), "\n" if ! $success;
}


> Save the program as test1.py
> Execute by
$ ./test.py myimage. jpeg
# Where myimage is the image which you want to update the metadata
(Date and time in this case)

6 comments:

Anonymous said...

I have been surfing online more than 2 hours today,
yet I never found any interesting article like
yours. It's pretty worth enough for me. Personally, if all web owners and bloggers made good content as you did, the net will be a lot more useful than ever before.

My web blog - majestic handy home products shed

Anonymous said...

Right here is the perfect blog for anyone who hopes to find out about this topic.
You realize so much its almost hard to argue with you (not
that I personally would want to…HaHa). You certainly put a fresh spin on
a subject that has been discussed for ages. Excellent stuff,
just excellent!

Also visit my web-site; discount office furniture atlanta

Anonymous said...

I agree on the superboy-prime issue. If each were fighting
to kill their opponents, then supes would instantly take it.

If he saw hulk beating up a city or something, then he would just smack hulk
around until realizing that there was no way to conquer him except by killing him.
Nevertheless, if they both acquired teleported into some pocket
universe, and were forced to fight every single other for
the demise using the loser getting his universe destroyed.
.. Superman has shown that he will cut loose
if sorely provoked. He would probably kill hulk if he had to protect his universe.
Then again, knowing superman, he would probably convince hulk to help him defeat the man who teleported them there, but if he had no choice, I believe that he would rapidly rip hulk aside ahead of he can get for
the required strength level.

Feel free to surf to my site ... premature ejaculation tips yahoo

Anonymous said...

Destroy China! Kill all Chinese all over the planet!


my webpage ... 2 girls teach sex pdf

Anonymous said...

Wonderful publish, extremely insightful. I ponder why the
other experts of the sector don't realize this. You must proceed your writing. I am sure, you've a fantastic
readers' foundation currently!

My page :: arm muscles twitching

Anonymous said...

This article will help the internet viewers for building
up new weblog or even a weblog from start to end.



Look at my web page :: attraction isn't a choice david deangelo pdf