42 lines
1.9 KiB
Bash
Executable File
42 lines
1.9 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
chrnx_image_script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
chrnx_image_root=$(dirname -- "$chrnx_image_script_dir")
|
|
chrnx_image_output="$chrnx_image_root/assets/images/generated"
|
|
chrnx_image_tmp=$(mktemp -d "${TMPDIR:-/tmp}/chrnx-images.XXXXXX")
|
|
trap 'rm -rf -- "$chrnx_image_tmp"' EXIT HUP INT TERM
|
|
|
|
for chrnx_image_tool in sips cwebp avifenc; do
|
|
if ! command -v "$chrnx_image_tool" >/dev/null 2>&1; then
|
|
echo "Required image tool is missing: $chrnx_image_tool" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
mkdir -p -- "$chrnx_image_output"
|
|
|
|
chrnx_build_portrait() {
|
|
chrnx_image_basename=$1
|
|
chrnx_image_source="$chrnx_image_root/assets/images/$chrnx_image_basename.png"
|
|
if [ ! -f "$chrnx_image_source" ]; then
|
|
echo "Source portrait is missing: $chrnx_image_source" >&2
|
|
exit 1
|
|
fi
|
|
|
|
for chrnx_image_width in 384 768; do
|
|
chrnx_image_resized="$chrnx_image_tmp/$chrnx_image_basename-$chrnx_image_width.png"
|
|
sips --resampleWidth "$chrnx_image_width" "$chrnx_image_source" --out "$chrnx_image_resized" >/dev/null
|
|
cwebp -quiet -preset picture -q 78 -alpha_q 90 -m 6 -metadata none "$chrnx_image_resized" -o "$chrnx_image_output/$chrnx_image_basename-$chrnx_image_width.webp"
|
|
avifenc --ignore-exif --ignore-xmp --ignore-icc --qcolor 58 --qalpha 85 --speed 6 "$chrnx_image_resized" "$chrnx_image_output/$chrnx_image_basename-$chrnx_image_width.avif" >/dev/null
|
|
done
|
|
}
|
|
|
|
for chrnx_image_topic in code gaming life literature podcasts research; do
|
|
chrnx_build_portrait "alter-ego-$chrnx_image_topic"
|
|
printf '{\n\t"source": "alter-ego-%s.png",\n\t"formats": [ "avif", "webp" ],\n\t"widths": [ 384, 768 ]\n}\n' "$chrnx_image_topic" > "$chrnx_image_output/alter-ego-$chrnx_image_topic.json"
|
|
done
|
|
|
|
chrnx_build_portrait "the-no-names-musician-cutout"
|
|
printf '{\n\t"source": "the-no-names-musician-cutout.png",\n\t"formats": [ "avif", "webp" ],\n\t"widths": [ 384, 768 ]\n}\n' > "$chrnx_image_output/the-no-names-musician-cutout.json"
|