Getting Exif information

Top Japanese page




Overview

Getting Exif information from a Jpeg file.

Flow

  1. Load Image::ExifTool
  2. Open an image file and make an object from it
  3. Get Exif information from the object of the image
  4. Close the file
  5. Display the obtained Exif information

A sample code

 use Image::ExifTool;
 
 my $img;
 open ($img, "< file.jpg");
 
 my $exifinfo = Image::ExifTool->new->ImageInfo($img);
 close($img);
 
 foreach (sort keys %$exifinfo) {
     print "$_ -----> $$exifinfo{$_}\n";
 }

Description of the code

 use Image::ExifTool;

Load Image::ExifTool.

 my $img;
 open ($img, "< file.jpg");

Open the jpeg file. Where the file name is file.jpg and file handle is $img.

 my $exifinfo = Image::ExifTool->new->ImageInfo($img);

Create an object from Image::ExifTool. The ImageInfo method takes a file handle and returns a reference of the hash into $exifinfo. The Exif information contains in the hash referred by the reference. In this example, Making the object and executing the ImageInfo method is done in one line. If you want to do it separately,

 my $e = Image::ExifTool->new;
 my $exifinfo = $e->ImageInfo($img);

you can do as above.

 close($img);

Close the file.

 foreach (sort keys %$exifinfo) {
     print "$_ -----> $$exifinfo{$_}\n";
 }

Display Exif information one by one from the hash. Just to consistent the outout order, this example uses a sort.