raw2preview: Refactor and add functionality

Add support for multiple arguments.
Make the code more modular and extendable for other raw formats by
keeping the differentiation code in the main loop and removing the
hardcoded file extension from extractRAW().
Write some of the EXIF tags that the original raw image had into the JPG
like Orientation and some technical details.
This commit is contained in:
2020-10-06 01:03:31 +02:00
parent 9bb96e26e7
commit d5efedf872

View File

@@ -1,34 +1,39 @@
#!/bin/sh #!/bin/bash
errorAndExit () { TAGS_TO_TRANSFER=(
printf "\033[1;31m$1\033[0m" >&2 -Orientation
exit $2 -CreateDate
} -ExposureTime
-FNumber
-ISO
-FocalLength
)
extractRAW () { extractRAW() {
if [ -r "$1" ]; then [[ -n "$1" ]] || return
if [ "$1" != "${1%CR2}" ] && [ ! -f "${1%CR2}JPG" ]; then prev="./JPGs/${1%.*}.JPG"
exiftool "$1" -PreviewImage -b > "${1%CR2}JPG" if [[ ! -e "$prev" ]]; then
echo "${1%CR2}JPG" mkdir -p JPGs
else exiftool -progress \
printf "\033[1;31mPreview for $1 exists already.\n\033[0m" >&2 -b \
fi -PreviewImage \
"$1" \
> "$prev"
exiftool -overwrite_original \
-tagsFromFile="$1" \
"${TAGS_TO_TRANSFER[@]}" \
"$prev"
fi fi
} }
if [ $# -ne 1 ] || [ ! -r "$1" ]; then for file; do
errorAndExit "Please specify one readable file.\n" 1 if [[ "$(file -b --mime-type "$file")" = "image/x-canon-cr2" ]]; then
fi extractRAW "$file"
elif [[ "$(head -1 "$file")" = "#Geeqie collection" ]]; then
if [ "$(file -b --mime-type "$1")" = "image/x-canon-cr2" ]; then while read line; do
extractRAW "$1" extractRAW "$file"
elif [ "$(head -n 1 "$1")" = "#Geeqie collection" ]; then done <"$(sed -E '/^#/d;s/(^"|"$)//g' "$file")"
while read line; do else
if echo "$line" | grep -qv "^#"; then >&2 printf "Unrecognized format: $file\n"
line="${line#\"}" fi
extractRAW "${line%\"}" done
fi
done < "$1" # <"$(sed -r '/#/d;s/(^"|"$)//g' "$1")"
else
errorAndExit "Please specify either a CR2 or a geeqie collection\n" 1
fi