Files
fetch-achewood/postprocess.sh

48 lines
1.2 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
# Postprocesses all fetched comics from the fetch-comics.py file
set -euo pipefail
HERE="$(dirname "$0")"
DATA_DIR="$HERE/data"
IMAGE_DIR="$DATA_DIR/images"
OUT_DIR="$HERE/out"
#alt_json="$HERE/alt_text.json"
alt_json="$DATA_DIR/alt_text.json"
if [[ ! -f "$alt_json" ]]; then
echo "Could not find $alt_json - have you run the fetch script?"
exit 1
fi
mkdir -vp "$OUT_DIR"
# Get the list of all comic dates
readarray -t dates < <(jq -r 'keys[]' < "$alt_json")
#echo ${#dates[@]}
for date in "${dates[@]}"; do
echo -n "Processing comic $date ... "
image_in="$IMAGE_DIR/$date.gif"
image_out="$OUT_DIR/$date.png"
if [[ -f "$image_out" ]]; then
echo "already exists, skipping"
continue
fi
alt_text="$(jq -r ".[\"$date\"]" < "$alt_json")"
if [[ -z "$alt_text" ]]; then
convert "$image_in" \
-background white -alpha remove -alpha off \
"$image_out"
else
convert "$image_in" \
-background white -alpha remove -alpha off \
-gravity center \
-pointsize 12 -size 360x caption:"$alt_text" \
-append \
"$image_out"
fi
echo "OK"
done