#!/usr/bin/perl # This program is provided under no warranty and use it at your own risk. Not that # there is any known issue in this program. You can do anything you want with this # program. # # Given a file name, create a thumbnail image and a larger image with the borders. # The second argument is optional. It should be the directory where the source file # is available. # e.g. # prep_for_web_gallery.pl Garter_Snake.tif # prep_for_web_gallery.pl Toronto_Snake.bmp cdrom # What you want to do is to run the script under a "foreach" command of csh # with the filenames of the images (to be published) stored in a text file. # Customization: # 1. If you do not want to run the command and only want to see the commands that # will be run make $production = 0; # 2. Change the variables $comment and $copyright to what you wish. use strict; use warnings; my $dirname; my $pathname; my $src_pathname; my $filename; my $extension; my $comp_im_name; my $pub_im_name; my $tn_im_name; my $cmd; my $production = 1; my $comment = ' (c) mydomain.com'; my $copyright = '(c) mydomain.com'; my $comment_params = " -comment \"$comment\""; # Parameters to resize and compress the original image. my $im_params = "-interlace \"NONE\" -size \"600x600>\" -resize \"600x600>\" -density \"150x150\""; # Parameters to be supplied to create the thumbnail image. my $tn_params = "-interlace \"NONE\" -size \"120x120>\" -resize \"120x120>\" -density \"72x72\" +profile \"*\" "; $tn_params .= $comment_params; # Parameters to be supplied to create a publishable compressed image. my $pub_im_params = " -bordercolor black -border 12x12 -frame 3x3+1+1 -antialias -font helvetica -fill grey -pointsize 10 -gravity \"South\" -draw \'text 0,2 \"$copyright\"\' $comment_params"; sub Usage { print "Arguments:\n"; print "1. name of the image file (source)\n"; print "2. (optional) name of the directory containing the source image.\n"; } sub trim { my @out = @_; for (@out) { s/^\s+//; s/\s+$//; } return wantarray ? @out : $out[0]; } # Check if source directory has been supplied. $pathname = $ARGV[0] || ""; $dirname = $ARGV[1] || ""; if ($pathname eq "") { Usage; exit (1); } $pathname = trim($pathname) if $pathname; $dirname = trim($dirname) if $dirname; if ( $dirname =~ m/\/\z/) { chop ($dirname); } # extract the filename and the extension. if ($pathname =~ m/(.*)\.(.*)\z/) { $filename = $1; $extension = $2; } # construct the filename for the compressed image. if ($dirname eq "") { $src_pathname = "$pathname"; } else { $src_pathname = "$dirname/$pathname"; } $pub_im_name = "$filename.jpg"; $comp_im_name = "comp_$filename.jpg"; $tn_im_name = "tn_$filename.jpg"; # First create the compressed image of low density. $cmd = "convert "; $cmd .= $im_params; $cmd .= " $src_pathname $comp_im_name"; print "# Creating compressed image...\n"; print "$cmd\n"; system ($cmd) if $production; # Create the thumbnail from the compressed image $cmd = "convert "; $cmd .= $tn_params; $cmd .= " $comp_im_name $tn_im_name"; print "# Creating thumbnail image...\n"; print "$cmd\n"; system ($cmd) if $production; # Create the final published image $cmd = "convert "; $cmd .= $pub_im_params; $cmd .= " $comp_im_name $pub_im_name"; print "# Creating the publishable image...\n"; print "$cmd\n"; system ($cmd) if $production; # END