Files
dotfiles/.local/bin/raw2preview
druckdev 4650ebe641 bin:raw2preview: Add support of TIFFs
I know that TIFFs are not strictly speaking raw files. But I don't
bother remaining the script.
2021-07-13 17:01:54 +02:00

52 lines
955 B
Bash
Executable File

#!/bin/bash
TAGS_TO_TRANSFER=(
-Orientation
-CreateDate
-ExposureTime
-FNumber
-ISO
-FocalLength
)
extractRAW() {
[[ -n "$1" ]] || return
prev="./JPGs/${1%.*}.JPG"
if [[ ! -e "$prev" ]]; then
exiftool -progress \
-b \
-PreviewImage \
"$1" \
> "$prev"
exiftool -overwrite_original \
-tagsFromFile="$1" \
"${TAGS_TO_TRANSFER[@]}" \
"$prev"
fi
}
mkdir -p JPGs
for file; do
[[ -f $file ]] || continue
mime="$(file -b --mime-type "$file")"
if [[ $mime = image/x-canon-cr2 ]]; then
extractRAW "$file"
elif [[ $mime = image/tiff ]]; then
prev="./JPGs/${file%.*}.JPG"
[[ -e "$prev" ]] || convert "$file" "$prev"
elif [[ "$(head -1 "$file")" = "#Geeqie collection" ]]; then
while read line; do
extractRAW "$file"
done <"$(sed -E '/^#/d;s/(^"|"$)//g' "$file")"
else
>&2 printf "Unrecognized format: $file\n"
fi
done
rmdir JPGs >/dev/null 2>&1