Image::DB - Perl module to acess image databases

This module provides methods to query image databases for meta information of images (description, location, keywords, etc.), to manipulate these information and to transfer these information from one image db to another.

I needed this module to transfer my image descriptions from ACDSee to GThumb some time ago and now to put the data from GThumb into IPTC tags (stored inside the image file).

The ilocate program - contained in the distribution as a programming example - searches for all images on your disk (from a start directory downwards) and creates a image information cache. Afterwards it's fairly easy to find pictures. ad-hoc. So far it is a command line tool, but a nice GUI might be a future enhancement ;-).

See the module documentation for further information:

Using the Image::DB module these tasks very simple. Two examples should illustrate this.

Search for an image file

use Image::DB;

my $outputpattern = "%f: %d{%Y-%m-%d}, %K"; # just an example
                        # prints filename, date and keywords

my $pattern = $ARGV[0] || "//Image";
foreach my $image (Image::DB::query($pattern))
{
    # do some formatting
    my $outstring= $outputpattern;
    $outstring =~ s/\%d\{([^}]+)\}/time2str($1, $image->getDate())/eg;
    $outstring =~ s/\%p/$image->getFoldername()/eg;
    $outstring =~ s/\%f/$image->getFilename()/eg;
    $outstring =~ s/\%F/$image->getAbsoluteFilename()/eg;
    $outstring =~ s/\%t{([^}]+)}/$image->getProperties()->{$1}/eg;
    $outstring =~ s/\%K/$image->getKeywords()/eg;
    $outstring =~ s/\%W/$image->getPlace()/eg;
    $outstring =~ s/\%E/$image->getDescription()/eg;
    $outstring =~ s/\%Z/%Y-%m-%d %T/;
    print "$outstring\n";
}

Convert image meta data from GThumb to IPTC

use Image::DB;
#...
foreach my $image (Image::DB::query("//Image[Keywords='Family']")) {
    print "Inspecting '" . $image->getAbsoluteFilename() .  "'";

    if (Image::DB::Backend::getInstance("IPTC")->knowsFile($image)) {
            print "File contains IPTC info ... skipping";
    }

    if (Image::DB::Backend::getInstance("GThumb")->knowsFile($image)) {
        my $gthumbimageobj = Image::DB::File->new($image, "GThumb");

        print "Write IPTC info";
        # the data is stored implicitly when destroying the newly created object
        Image::DB::File->new($gthumbimageobj, "IPTC");
    }
    else {
        print "No GThumb data available ... skipping";
    }
}
Note, that you don't need to save the data, they are written to the file as soon the Image::DB::File object is destroyed.
Have fun!