Add gitignore, fetch script, and postprocess script
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
47
postprocess.sh
Executable file
47
postprocess.sh
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/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 background \
|
||||
"$image_out"
|
||||
else
|
||||
convert "$image_in" \
|
||||
-background white -alpha background \
|
||||
-gravity center \
|
||||
-pointsize 12 -size 360x caption:"$alt_text" \
|
||||
-append \
|
||||
"$image_out"
|
||||
fi
|
||||
|
||||
echo "OK"
|
||||
done
|
||||
Reference in New Issue
Block a user