Created
September 18, 2021 15:59
-
-
Save xanoni/ab3bf42f91ed2a301a3582093e3b0f2e to your computer and use it in GitHub Desktop.
Sanitize image files (strip tags and pick random filename)
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
#! /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