Skip to content

Instantly share code, notes, and snippets.

@xanoni
Created September 18, 2021 15:59
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 xanoni/ab3bf42f91ed2a301a3582093e3b0f2e to your computer and use it in GitHub Desktop.
Save xanoni/ab3bf42f91ed2a301a3582093e3b0f2e to your computer and use it in GitHub Desktop.
Sanitize image files (strip tags and pick random filename)
#! /usr/bin/env -S bash -e
function rand-rename {
local oldnames=("${@}")
local newname
local baseascii
for oldname in "${oldnames[@]}"; do
if [ -f "${oldname}" ]; then
baseascii="$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | \
sha256sum | head -c15)"
newname="$(dirname "${oldname}")/${baseascii}.${oldname##*.}"
mv "${oldname}" "${newname}"
echo -en "${oldname}\t\t==>\t\t${newname}\n"
fi
done
}
function img-exifkill {
echo -en "\nPass 1 (exiftool) ...\n\n"
exiftool -overwrite_original_in_place -all='' "${@}" # -EXIF=''
echo -en "\nPass 2 (exiv2) ...\n\n"
exiv2 rm "${@}"
echo -en "\n"
}
function img-sanitize {
echo -en "\n>>> Cleaning EXIF tags ...\n\n"
img-exifkill "${@}"
echo -en "\n>>> Renaming ...\n\n"
rand-rename "${@}"
echo -en "\nDone!\n\n"
}
img-sanitize "${@}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment