Skip to content

Instantly share code, notes, and snippets.

@mgunneras
Created January 17, 2015 22:07
Show Gist options
  • Save mgunneras/7ab41b1aa55f75a2260e to your computer and use it in GitHub Desktop.
Save mgunneras/7ab41b1aa55f75a2260e to your computer and use it in GitHub Desktop.
Convert image files into smaller thumbnails using Imagemagick
#! /bin/bash
#
# Recursively convert image files in IN_DIR into smaller jpegs
# Copy all other files straight over
# Resulting files (including folder structure) ends up in in IN_DIR/../thumbs/
IN_DIR=$1
is_image() {
local name=$1
file "$name" | grep image > /dev/null
}
#replicate dir structure
pushd "$IN_DIR"
mkdir -p "../thumbs"
find . -type d ! -name .| while read DIR; do
mkdir -p "../thumbs/${DIR}"
done
#convert files
find . -type file| while read FILE; do
if is_image "$FILE"; then
convert "$FILE" -resize 60x60% -quality 70 -format jpg "../thumbs/${FILE}"
else
cp "$FILE" "../thumbs/${FILE}"
fi
done
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment