#!/usr/bin/perl ####!C:\Perl64\bin\perl.exe # makeJpegs.pl # for Windows # to create jpegs for upload into Acumen ##Copyright (c) 2009, The University of Alabama Libraries. ## Contributed by Jody DeRidder, 12/04/09. ##All rights reserved. ##Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: ## * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. ## * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the ## distribution. ## * Neither the name of The University of Alabama Libraries nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. ##THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, ##THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ##CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, ##PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ##LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, ##EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # jody DeRidder, 12/4/09 # asks for path to imageMagick executable # asks for scans directory to work # outputs content into upload folder in that directory # making 3 versions of jpegs # designed for Cabaniss # location hardcoded here: $base = "..\\..\\..\\Digital_Coll_Complete\\u0003_0000252_Cabaniss\\"; $newdir = $base."Upload\\"; opendir(BASE, $base) or die "can't open $base\n"; while ($file = readdir(BASE)){ # print "looking at $file\n"; if ($file =~ /^\./ || $file =~ /Upload/i){next;} # skip dot files $path = $base.$file; if (-d $path){ push (@dirs, $file); } } close(BASE); print "I'm testing $base. \n Here are the directories there. \n"; $dircount = scalar @dirs; for ($i = 1; $i <= $dircount; $i ++){ print $i.") ".$dirs[$i-1]."\n"; } #foreach (@dirs){ print "$_\n";} print "\nWhich directory do you want? \n Type the number and press enter:\n"; $num = ; chop $num; $num --; $mybase = $base.$dirs[$num]."\\"; $thisdir = $mybase; $myval = 1; print "I'm testing $thisdir.\n What is the exact path to the ImageMagick folder?\n"; $im = ; chomp ($im); if (! ($im =~ /\\$/)){ $im .= "\\"; } if (! ($im =~ /ImageMagick/)){ $im .= "ImageMagick\\convert.exe"; } else{ $im .= "\\convert.exe"; } $im =~ s,\\,\\\\,g; # add backslashes $im =~ s,\\\\+,\\\\,g; #take out excess if (! -e $im){ print "unable to locate $im. \n"; sleep(3); exit; } #else { print "I found $im!\n Please check uploads directory in a few seconds\n";} push (@dirlist, $thisdir); foreach $dir (@dirlist){ opendir (DIR, $dir) or die "can't look through $dir\n"; while ($file = readdir(DIR)){ # print "looking at $file in $dir\n"; if ($file =~ /^\./ ){ next; } # skip dot files $path = $dir."\\".$file; if ( -d $path){ # must be a directory push (@dirlist, $path); next; } #if ($file =~ /^[a-z]{1}\d{4}/ || $file =~ /^\d{3,7}$/){ # must match pattern u0003, p0004,(etc) 3-7 numbers, etc elsif ($file =~ /^(.*)\.tif/){ # tif file $filenum = $1; print "$file from $dir to $newdir\n"; # create the derivatives if they don't exist # name them appropriately and put them in the new location $path = qq($path); $big = $newdir."\\".$filenum."_2048.jpg"; $mid = $newdir."\\".$filenum."_512.jpg"; $small = $newdir."\\".$filenum."_128.jpg"; $big = qq($big); $mid = qq($mid); $small = qq($small); if (! -e $big){ `$im $path -strip -density 96 -resample 96x96 -resize 2048x2048 -filter Cubic -quiet $big`; } if (! -e $mid){ `$im $path -strip -density 96 -resample 96x96 -resize 512x512 -filter Cubic -quiet $mid`; } if (! -e $small){ `$im $path -strip -density 96 -resample 96x96 -resize 128x128 -filter Cubic -quiet $small`; } } } close(DIR); }