#!/usr/bin/perl -w use strict; use Image::Magick; # Options my $font_face = 'Arial'; # Font face my $font_size = 40; # Font size my $font_color = 'red'; # Font color my $coordinates = '100,100'; # Pixels from top-left corner to place annotation my $file_prefix = 'annotated_';# Prefix for modified image filenames my $max_width = 800; # Maximum width in pixels my $max_height = 600; # Maximum height in pixels my $jhead = `which jhead 2>/dev/null`; # Make sure that jhead exists chomp($jhead); unless ($jhead && -e $jhead) { print "This script requires jhead executable.\n"; print "Get jhead from http://www.sentex.net/~mwandel/jhead/\n"; exit(1); } # Make sure that at least one image is given unless (@ARGV) { print "\nUsage: $0 somefile1 somefile2 somefile3\n\n"; exit(1); } foreach my $image (@ARGV) { print "Processing $image\n"; my $dest_image = $file_prefix . $image; my $picture = new Image::Magick; $picture->Read($image); # Get image info my ($width, $height, $size, $format) = $picture->Ping($image); # Find out if it is portrait or landscape my $geometry; if ($width >= $height) { $geometry = '>' . $max_width . 'x' . $max_height; } else { $geometry = '>' . $max_height . 'x' . $max_width; } print "Scaling image $image to $geometry\n"; $picture->Scale($geometry); # Get date from EXIF data my @exif_data = `$jhead $image`; my $date = ''; foreach my $line (@exif_data) { chomp($line); if ($line =~ m/^Date/) { $date = $line; $date =~ s/^Date(.*:\s+)?//; last; } } # If date found in EXIF, then annotate image with it if ($date) { print "Annotating $image with $date\n"; $picture->Draw( primitive=>'text', fill=>$font_color, bordercolor=>$font_color, points=>"$coordinates '$date'", font=>$font_face, pointsize=>$font_size, method=>'Floodfill', ); } # Save changes $picture->Write($dest_image); }