Skip to content

Instantly share code, notes, and snippets.

@mchow01
Last active December 25, 2015 11:19
Show Gist options
  • Save mchow01/6968354 to your computer and use it in GitHub Desktop.
Save mchow01/6968354 to your computer and use it in GitHub Desktop.
This shell script will batch create image thumbnails, 100x100, preserving aspect ratio, for images in a directory of images. imagemagick is required! To run: bash ./batch_thumbnail_creator.sh
#!/bin/sh
for filename in *
do
if [ "$filename" != "cache" -a "$filename" != "create_cache.sh" -a ! -f "cache/${filename}"
]; then
mkdir "cache/${filename}"
fi
done
for filename in **/*
do
thebasename="${filename%.*}"
extension="${filename##*.}"
thumbname="cache/${thebasename}-thumb.${extension}"
if [ "$extension" == "jpg" -o "$extension" == "png" -o "$extension" == "jpeg" ]; then
convert "${filename}" -thumbnail '100x100' "${thumbname}"
fi
done
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment