#!/usr/bin/perl ####!C:\Perl64\bin\perl.exe # makeJpegs.pl --- NOT YET WORKING # for Windows # to create jpegs for upload into Acumen # 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); }