Quite often i find myself wanting to resize a whole directory of images. Rather than opening them all in the gimp, i do it through the command line. I seem to do this often enough that it’s worth recording here, for my own reference as well as for anybody else who would find it useful.
First of all, you need imagemagick.
sudo apt-get install imagemagick
Change directory to where the images are and create a subdirectory for the resized versions.
cd ~/Photos/2010/04/05 mkdir resized
My phone likes to put spaces in file names which really confuses things, so i convert them to underscores. You can skip this step if your filenames contain no spaces.
for image in *.jpg; do mv "$image" `echo $image | tr ' ' '_'`; done
Now for the clever bit: i run convert command on the image files, resizing them to 1024px and saving with a quality of 80%.
for image in *.jpg; do convert $image -resize 1024 -quality 80 resized/$image; done
Lovely wonderful linux! :D
One thing to note: it always resizes along the top edge, which may not be the longest edge. If you have a portrait file which is 1536×2048 it comes out at 1024×1365 (not 768×1024 as you might have expected).
The resize option can take a percentage, so if you know all your images are the same size then you could just send a 50% to reduce to half size.
for image in *.jpg; do convert $image -resize 50% -quality 80 resized/$image; done
Imagemagick is super-incredible-awesome so there probably is a way to deal with differently sized images at different orientations. If anybody knows, please add it in the comments! :)