Created
August 30, 2016 18:21
-
-
Save hugowetterberg/02b462ba420f3428b2ed48cb886ae90e to your computer and use it in GitHub Desktop.
Guess iptc encoding
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 | |
set -e | |
exec 3>&1 # make stdout available as fd 3 for the result | |
exec 1>&2 # redirect all output to stderr for logging | |
image=$1 | |
debug='n' | |
# Check if the first parameter was '-v' then we check for the image in | |
# the second parameter and enable debugging. | |
if [ "${image}" == '-v' ]; then | |
image="${2}" | |
debug='y' | |
fi | |
# Check if we got an image | |
if [ -z "$image" ]; then | |
echo "usage: ${0} [-v] <path/to/image>" | |
exit 1 | |
fi | |
# Yay! Table driven testing in bash! | |
# Its really only the first one that's a real case, the other | |
# ones are just there to illustrate the point. | |
# The fields are iptcEncoding,template,contains | |
table=$(cat <<EOF | |
mac,\$copyrightnotice,BILDBYRÅN | |
mac,\$caption-abstract,Göteborg | |
mac,\$city,Malmö | |
EOF | |
) | |
# Iterate over the rows to see if we get a hit | |
echo "${table}" | while IFS="," read iptcEnc template contains | |
do | |
# run exiftool with the print format template (-m ignores minor errors like | |
# the referenced field not being defined) | |
result=$(exiftool -m -charset iptc=${iptcEnc} -p ${template} ${image}) | |
# ...check if the test case string is in our result | |
if [[ "${result}" == *"${contains}"* ]]; then | |
if [ $debug == "y" ]; then | |
# print som info on the match if we're running with a debug flag | |
echo identified iptc charset \"$iptcEnc\" from test-case \"$template\" contains \"$contains\" | |
fi | |
# return the detected encoding and exit | |
echo $iptcEnc >&3 | |
exit 0 | |
fi | |
done |
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
encParam="" | |
iptcEnc=$(./check_iptc_encoding -v ${1}) | |
if [ ! -z "${iptcEnc}" ]; then | |
encParam="-charset iptc=${iptcEnc}" | |
fi | |
exiftool -j ${encParam} $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment