#!/usr/bin/perl # # Shappyhopper Annotate V2.0 (an update to the abortion previously released on the web) # # A Perl Script to Annotate an Entire Directory of Images with imagemagick. # # Written By Edwin Hopper www.shappyhopper.co.uk June 2007 # # This script requires the Image Magick Perl Libraries as well as a perl interpreter # This script must be executed on a directory that only contains # image files supported by Image Magik (e.g. .jpg .gif). use Image::Magick; ########################################################################################## #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # Enter Variables Here !!!YOU MUST ENTER THE CORRECT VARIABLES OR THIS WILL NOT WORK!!!! # # # AnnotateText is the text you want to have printed on the Image # TextColour is the colour you want the text to be (i.e. Black, white, red, gold) # TextSize is how big you want the text to be # TextLocation is where you want the text to be (i.e. North=Top, South=Bottom SouthWest=Bottom Left) # GeometryX is the distance in the X axis from the Location Start Point (e.g. distance from the left # edge when using NorthWest, or the distance from the right edge when using NorthEast) # GeometryY is the distance in the Y axis from the Location start point (e.g. distance from the top # edge when using North, or the distance from the bottom when using South) $AnnotateText="(C) E Hopper - www.shappyhopper.co.uk"; $TextColour="gold"; $TextSize="14"; $TextLocation="SouthWest"; $GeometryX="+20"; $GeometryY="+20"; #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! End of Variables!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ######################################################################################### ######################################################################################### ######################################################################################### # # First We Open the local directory and copy the contents into an array # $DirToGet="."; opendir(IMD, $DirToGet) || die("Cannot Open Directory"); @thefiles=readdir(IMD); closedir(IMD); # # Now we process the contents of the array, and thus the images # $GeometryCombine="$GeometryX$GeometryY"; print "\n\n#############################################################################"; print "\n!!!!!!!!!!!!!!!!!!!!!!!!!!Starting Annotation!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n"; print " This may take some time depending on the size\n"; print " and number of files."; print "\n\n\n This script has found the following files in the target directory:\n"; # # Print the contents of the directory for later troubleshooting # $totalcount=0; foreach $f(@thefiles) { unless ( ($f eq ".") || ($f eq "..") || ($f =~/.pl/) ) { $totalcount++; print " $totalcount. $f\n"; } } print "\n\n Begining Annotation of $totalcount files\n"; print " All files will be annotated with $AnnotateText in $TextColour\n"; # # Now annotate the files # $counteach=0; foreach $f(@thefiles) { unless ( ($f eq ".") || ($f eq "..") || ($f =~/.pl/) ) { $counteach++; # Read in the file print "\n\n ########################################################\n"; #This section opens the image print " Reading in $f (file $counteach of $totalcount)\n"; my $thumb= new Image::Magick; open(IMAGE, "$f"); $thumb->Read(file=>\*IMAGE); close(IMAGE); #And annotate the image print " Annotating image\n"; $thumb->Annotate(text=>$AnnotateText,geometry=>$GeometryCombine,font=>'Generic.ttf', fill=>$TextColour,gravity=>$TextLocation,pointsize=>$TextSize); #Write it to the gallery directory print " Writing Image\n"; $thumb->Write("./$f"); print " ########################################################\n"; } } print "\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!Annotation Completed!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"; print "\n#############################################################################\n\n";