Created
January 17, 2015 22:07
-
-
Save mgunneras/7ab41b1aa55f75a2260e to your computer and use it in GitHub Desktop.
Convert image files into smaller thumbnails using Imagemagick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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