Created
February 16, 2017 21:36
-
-
Save MagnetonBora/2434b1f323987c13ab70aae44e639f9f to your computer and use it in GitHub Desktop.
Convert banch of pictures to another format
This file contains 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 | |
# http://mywiki.wooledge.org/BashFAQ/001 | |
# http://askubuntu.com/questions/343727/filenames-with-spaces-breaking-for-loop-find-command | |
function usage { | |
echo "Example usage: convert.sh dir base-extension target-extenstion" | |
} | |
if [[ -z $1 ]] | |
then | |
echo "What location should I take?" | |
usage | |
exit 1 | |
fi | |
if [[ -z $2 ]] | |
then | |
echo "Which file extension should I take?" | |
usage | |
exit 1 | |
fi | |
if [[ -z $3 ]] | |
then | |
echo "Which file type should I convert to?" | |
usage | |
exit 1 | |
fi | |
find $1 -type f -name "*.$2" -print0 | while IFS= read -r -d '' filename; do | |
convert "$filename" "`basename -s .$2 "$filename"`.$3" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment