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:
@@ -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
|
|
||||||
extractRAW "$1"
|
|
||||||
elif [ "$(head -n 1 "$1")" = "#Geeqie collection" ]; then
|
|
||||||
while read line; do
|
while read line; do
|
||||||
if echo "$line" | grep -qv "^#"; then
|
extractRAW "$file"
|
||||||
line="${line#\"}"
|
done <"$(sed -E '/^#/d;s/(^"|"$)//g' "$file")"
|
||||||
extractRAW "${line%\"}"
|
else
|
||||||
|
>&2 printf "Unrecognized format: $file\n"
|
||||||
fi
|
fi
|
||||||
done < "$1" # <"$(sed -r '/#/d;s/(^"|"$)//g' "$1")"
|
done
|
||||||
else
|
|
||||||
errorAndExit "Please specify either a CR2 or a geeqie collection\n" 1
|
|
||||||
fi
|
|
||||||
|
|||||||
Reference in New Issue
Block a user