photosite/scripts/img.sh

37 lines
791 B
Bash

#!/bin/bash
set -e
source .env
INPUT="${1}"
ID="${2}"
EXIF="${3}"
SIZES=(
"thumb:420"
"full:2000"
)
function img () {
convert "${1}" -colorspace LAB -filter Lanczos -resize ${3}x -strip -quality 86 -colorspace sRGB "${2}"
echo "${1} -> ${2}"
}
mkdir -p "${WWW}/img/"
mkdir -p "${PHOTOS}/"
for sizeRaw in ${SIZES[@]}; do
sizeName=$(echo $sizeRaw | awk -F':' '{print $1}')
size=$(echo $sizeRaw | awk -F':' '{print $2}')
name=$(basename "${1}")
name=${name%.*}
output="${WWW}/img/${ID}_${sizeName}.jpg"
img "${1}" "${output}" "${size}"
if [[ -f "${WWW}/img/${ID}_${sizeName}-1.jpg" ]]; then
mv "${WWW}/img/${ID}_${sizeName}-0.jpg" "${WWW}/img/${ID}_${sizeName}.jpg"
rm "${WWW}/img/${ID}_${sizeName}-1.jpg"
fi
exiftool -overwrite_original -@ "${EXIF}" "${output}"
done