Skip to content

Instantly share code, notes, and snippets.

@naftulikay
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naftulikay/6e2591d38b3078cca13e to your computer and use it in GitHub Desktop.
Save naftulikay/6e2591d38b3078cca13e to your computer and use it in GitHub Desktop.
Image Metadata Cleaner
#!/bin/bash
# img-clean: remove ALL metadata from images
# requires ImageMagick
# A POSIX variable
OPTIND=1 # is reset in case getopts was already run
verbose=0
backup=0
exec_args=""
function show_help () {
echo "usage: img-clean [OPTION]... FILE..."
echo "Removes all image metadata from popular image formats."
echo
echo " -v Verbose output."
echo " -h Show this help text."
echo " -b Make a backup file postfixed with '.original' before modifying"
echo " image metadata."
echo
}
while getopts "hvb" arg ; do
case "$arg" in
h)
show_help
exit 0
;;
v)
verbose=1
exec_args="$exec_args -verbose"
;;
b)
backup=1
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
for file in "$@" ; do
if [ ! -f "$file" ]; then
echo "$file doesn't exist."
exit 1
fi
if [ $backup = 1 ] ; then
test $verbose = 1 && echo "Making backup to $file.original..."
cp "$file" "$file.original"
fi
test $verbose = 1 && echo "Cleaning metadata from $file..."
mogrify $exec_args -strip "$file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment