Skip to content

Instantly share code, notes, and snippets.

@MagnetonBora
Created February 16, 2017 21:36
Show Gist options
  • Save MagnetonBora/2434b1f323987c13ab70aae44e639f9f to your computer and use it in GitHub Desktop.
Save MagnetonBora/2434b1f323987c13ab70aae44e639f9f to your computer and use it in GitHub Desktop.
Convert banch of pictures to another format
#!/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