Facing the daunting task of resizing my recent photos to put on Flickr, I decided there must be a script out there to automate the process. I recall encountering one or two in the Ubuntu Forums.
Sure enough the information was there.
#!/bin/sh
# author: Bas Wenneker
# email: sabmann [ta] gmail [tod] com
# Use this script to batch resize all images in a folder.
# First open the folder and then use the script.
for file in `ls -l`
do
name=`echo $file | cut -f1 -d.`
convert -geometry 640×480 -quality 65 $file ${name}_640×480.jpg
done
The script is very straightforward, if you know a bit of bash dash (kudos: drone) scripting. I only know very little, but I think I’ve got this one down.
It simply loops through each file in the folder and removes the extension from the filename. It then uses the convert function to convert the file into a jpg of resolution 640×480 and quality 65, while renaming the file to include ‘_640×480′ at the end.
In the same thread on the Forums, some extra alterations were made to put the resized files in a sub folder, and to remove the EXIF information from the picture (if they are photos from your camera)
#!/bin/sh
# author: Bas Wenneker
# email: sabmann [ta] gmail [tod] com
# Use this script to batch resize all images in a folder.
# First open the folder and then use the script.
mkdir ./thumbnails
for file in `ls -l`
do
name=`echo $file | cut -f1 -d.`
convert -strip -geometry 800×600 -quality 80 $file ./thumbnails/${name}_800×600.jpg
done
I quite liked the ability to put the resized images in a subfolder (thumbnails), but not the removal of the EXIF information (-strip).
Another thing that I wasn’t interested in was that the script was a batch resize, which attempts to convert all the files in the folder, including videos. After chunking my computer up for some time on a large .AVI file, I decided that I would want this to be a once per file thing.
After changing these things and the changing the resolution/quality to what I wanted, I came up with this version of this script
#!/bin/sh
mkdir ./1024×768
for file
do
name=`echo $file | cut -f1 -d.`
convert -geometry 1024×768 -quality 100 $file ./1024×768/${name}_1024×768.jpg
done
I saved the script in a location, which will matter more later, and then applied execution permissions to it.
chmod +x resize1024×768
Once this was done I could run the script with the name of the photo as an argument (I guess you could call it that)
resize1024×768 img_0001.jpg
And hey presto, the photo is resized and placed in a sub folder 1024×768.
However this was only the starting point. The script was for designed to be accessed by Nautilus and the context (right-click) menu. I don’t have or want Nautilus, so …
While I could run the script straight from a bash prompt, I’d rather use it in conjunction with the Custom Actions in Thunar.
Stay tuned for that …




