hsarch-files/scripts/generate_thumbnails.sh
2023-07-15 13:59:44 +02:00

41 lines
887 B
Bash
Executable file

#!/usr/bin/bash
set -e
cd "$(dirname "$0")/.."
echo
echo "-> Generating Thumbnails"
if ! command -v convert >/dev/null; then
echo "Could not find ImageMagick."
echo "Please install it with 'sudo apt install imagemagick' and"
echo "enable PDF features in '/etc/ImageMagick-*/policy.xml'."
exit 1
fi
pdfs=()
get_image_path() {
echo "$1" | sed -r 's/(.+)\/pdf\/([^/]+)\.pdf/\1\/images\/\2.jpg/'
}
for file in data/*/pdf/*.pdf; do
image="$(get_image_path "$file")"
if [ ! -f "$image" ]; then
pdfs+=("$file")
fi
done
i=1
n="${#pdfs[@]}"
if [ "$n" == "0" ]; then
echo "(Nothing to do)"
else
for file in "${pdfs[@]}"; do
printf "Generating Thumbnail $i/$n for $file... "
convert -resize 500x700! -colorspace RGB -density 96 -quality 85 -background white -alpha remove "$file[0]" "$(get_image_path "$file")"
printf "Done\n"
i=$((i + 1))
done
fi