election-game/art/cards-small.sh

15 lines
811 B
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# 卡牌插圖的小圖(320×320):手牌、首頁那手牌只顯示約 120–160 px 寬,用小圖就好(web/src/game/art/CardArt.tsx 的 srcset)。
# 原圖 art/generated/<id>.png(沒有原圖就從 640 的 webp 縮)→ web/public/cards/sm/<id>.webp
# 用法:art/cards-small.sh [id…](不帶 id 是全部重做)
set -eu
here="$(cd "$(dirname "$0")" && pwd)"
cards="$here/../web/public/cards"
mkdir -p "$cards/sm"
if (($#)); then ids=("$@"); else mapfile -t ids < <(ls "$cards" | sed -n 's/\.webp$//p'); fi
for id in "${ids[@]}"; do
src="$here/generated/$id.png"
[[ -s "$src" ]] || src="$cards/$id.webp"
ffmpeg -loglevel error -y -i "$src" -vf "scale=320:320:flags=lanczos" -c:v libwebp -quality 78 -compression_level 6 "$cards/sm/$id.webp" && echo "ok $id"
done