#!/usr/bin/perl -w # # 5max - requires the imagemagick utilities # # dseelig - circa 2004 # # used to create thumbnails and medium-sized images from jpgs in the current directory # # commandline options: # 0: update: # move anything from current directory to orig create 5max and thumb # from anything in orig directory for all that don't exist already # # 1: rebuild: # move anything from current directory to orig create 5max and thumb # from anything in orig directory overwriting all images # # 2: dry-run: # say what you _would_ do use Cwd; # Configuration. The only thing you should need to modify: $dir = "5max"; $size = "500x500"; $thumbdir = "thumbs"; $thumbsize = "100x100"; $origdir = "orig"; $quality= "90"; # End Configuration. $o = $ARGV[0]; $root = getcwd(); print "Running 5max! root dir: $root\n"; if (!$o) { $o=0; } if ( ($o < 0) || ($o>2)) { die "incorrect usage"; } # do we need to test for this first? (make dirs) mkdir("$dir", 0755 ); mkdir("$thumbdir", 0755 ); mkdir("$origdir", 0755 ); # make all .JPGs entirely lowercase if (<*.JPG>) { system("rename 'y/A-Z/a-z/' *.JPG"); } # move all .jpg to origdir, then change into that dir and make thumbs, etc. if (<*.jpg>) { system("mv *.jpg $origdir"); } chdir("$root/$origdir"); while ($name = <*.jpg>) { #create the 5maxs if( ( -e "$root/$dir/$name" ) && ($o==0) ) { # we're just updating, but the resized image already exists, so do nothing } elsif ( $o==2) { print "dry run: would create $root/$dir/$name (maybe)\n"; } else { system "convert -size $size \"$name\" -quality $quality +profile '*' -resize $size \"$root/$dir/$name\""; print "."; } #create the thumbs if( ( -e "$root/$thumbdir/$name" ) && ($o==0) ) { # we're just updating, but the thumbnail already exists, so do nothing } elsif ( $o == 2 ) { print "dry run: would create thumb (maybe)\n"; } else { system "convert -size $thumbsize \"$name\" -quality $quality +profile '*' -resize $thumbsize \"$root/$thumbdir/$name\""; print "."; } } #now get rid of the extra thumbs/5maxs chdir("$root/$dir") or die "can't get into $root/$dir"; while ($name = <*.jpg>) { if( -e "$root/$origdir/$name" ) { } else { print "gratuitous image found in $root/$dir: $name\n"; unlink("$root/$dir/$name"); } } chdir("$root/$thumbdir") or die "can't get into $root/$thumbdir"; while ($name = <*.jpg>) { if( -e "$root/$origdir/$name" ) { } else { print "gratuitous image in $root/$thumbdir: $name\n"; unlink("$root/$thumbdir/$name"); } }