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.
40 lines
772 B
Bash
Executable File
40 lines
772 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
|
|
mkdir -p JPGs
|
|
exiftool -progress \
|
|
-b \
|
|
-PreviewImage \
|
|
"$1" \
|
|
> "$prev"
|
|
exiftool -overwrite_original \
|
|
-tagsFromFile="$1" \
|
|
"${TAGS_TO_TRANSFER[@]}" \
|
|
"$prev"
|
|
fi
|
|
}
|
|
|
|
for file; do
|
|
if [[ "$(file -b --mime-type "$file")" = "image/x-canon-cr2" ]]; then
|
|
extractRAW "$file"
|
|
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
|