#!/usr/bin/perl # resizeimages; # Last updated: 2006-12-29 =head1 resize images v1.0 reads image directory and resize and create thumbnail images. This script runs fine on any OS that has a working install of ImageMagick on it. =head1 ChangeLog 2006-12-29 :: 1.0 :: Initial release =head1 Author roqet =head1 Copyright Resizeimages Perl script copyright 2006 roqet . Resizeimages can be distributed and modified under the terms of the GNU General Public License: http://www.gnu.org/copyleft/gpl.html This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU General Public License for more details. Updates and other scripts and software available at: http://www.roqet.org/software.html ~~~ 'l' - =cut use File::Basename; if ($ARGV[0] eq '') { die "no parameters entered!\n to run: perl resizeimages.pl oldpath newpath\n"; } else { $oldpath = $ARGV[0]; $newpath = $ARGV[1]; } if ($ARGV[2] eq '-r') { $test = 0; } else { print "testmode = on, use \"-r\" for regular mode.\n"; $test = 1; } undef @oldimages; $filecount = 0; opendir(DIR, "$oldpath/") or die "can't opendir $path/: $!"; while (defined($file = readdir(DIR))) { if ($file =~ /.jpg/ or $file =~ /.JPG/) { push (@oldimages,"$file"); $filecount++; } } closedir(DIR); foreach $image (@oldimages) { chomp($image); print "image to convert: $image\n"; #thumbnail: #convert -size 120x120 20030217_dsc01705.jpg -resize 120x120 +profile "*" thumbnail.jpg #resize: #convert -size 614x819 20030217_dsc01705.jpg -resize 614x819 +profile "*" small.jpg #rotate: #convert -rotate 270 20030216_dsc01257.jpg small3.jpg # remove suffix ($imagename, $imagepath, $suffix) = fileparse($image, '\..*'); # create thumbnail command $imagenamesmall = $imagename . "_small.jpg"; $thumbnailcommand = "convert -size 120x120 $oldpath/$image -resize 120x120 +profile \"*\" $newpath/$imagenamesmall"; # create resize command $resizecommand = "convert -size 614x819 $oldpath/$image -resize 614x819 +profile \"*\" $newpath/$imagename.jpg"; if ($test) { print "test: $thumbnailcommand\n"; print "test: $resizecommand\n"; } else { system("$thumbnailcommand"); print "created thumbnail: $newpath/$imagenamesmall from $oldpath/$image\n"; system("$resizecommand"); print "created resize: $newpath/$image from $oldpath/$image\n"; } }