Categories
Linux shell

Create Thumbnails from a bunch of images

Linux Code snippet. Ever wated to batch create thumbnails? “musclecarr” posted this bash script to create thumbnails of all images of a specific type. It uses imagemagick and specifically the convert command. minor modifications done to it and comments added for easy understanding, here it is :

#!/bin/bash
# take argument or use current dir
DIR=${1:-`pwd`}
# create dir thumbs if doesnt exist
[ -d "$DIR/thumbs" ] || mkdir "$DIR/thumbs"
# error out if cant enter dir for some reason (permissions?)
cd "$DIR" || { echo >&2 "error: couldn't enter directory: $DIR"; exit 1;}
# For every file with extension XXX (jpg in this case)
for i in ./*.jpg; do
# Resize image to 100x100
convert "$i" -resize 100x100 "$DIR/thumbs/$i"
# profit? nah.
done

Leave a Reply

Your email address will not be published. Required fields are marked *