Adverts I have posted, and statistics

Come here looking for a free Science Fiction book by Edwin Hopper? click here to go to my Dad's site.

This page has been visited 934 times, as of Fri Sep 5 20:13:08 BST 2008 . Your IP Address is given as 38.103.63.60; this appears to be page number 6 for you today.

Disclaimer


Annotate Perl Script

Click here for a text file of this script, description below

This page used to contain a little script I wrote for annotating whole collections of images at once. That script was my first attempt at doing anything with Perl and Image Magick, was mostly stolen from other peoples scripts, and of the 1500 lines it contained I think one actually did anything.

I have since then written a new script which does the same thing, but far more neatly. The script is Perl and uses Image Magick. I'm sorry to say that I have only used this with SuSE Linux and its standard software; I have no idea if it will work with any other operating system or software, but would assume that whatever you do you will need a perl interpreter and Image Magick.

The script also has a nice little feature at the start. This opens a specified directory (in this case the local one) and then reads all the names of the files in it into an array. It can also be seen in the gallery script, where an extra line is added to sort the array alphabetically.

Speaking of the gallery script, if you want to annotate your images using this script before using that script to make a gallery don't bother; the gallery script contains an annotate feature.

To use the script copy it into your directory of images, edit it accordingly, and then run it. It is not a smart script so it will not be able to differentiate between the files it can annotate, and those it can't. If it comes across a file it cannot annotate (e.g. an HTML file) it will exit with an error. Also it does not save the original file so make sure you do not apply it to your only copy or copies!

Other than that enjoy.

Annotate Script

At the top of the page can be found a link to a text file of this script.

#!/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");
=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()
{
 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()
{
 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";


Page loading