#!/bin/zsh # 用本機 Grok Build(grok CLI 的 image_gen)產生一張卡牌插圖:gen-card-grokcli.sh <題材> # 只開放生圖工具(--allow imagine),不讓它執行指令;圖存在 grok 自己的 session 資料夾,這裡再轉檔。 # 原圖存 art/generated/.png,網頁用的縮圖存 web/public/cards/.webp(和 gen-card.sh 一樣) set -u id="$1"; subject="$2" here="${0:A:h}" out="$here/generated/$id.png" web="$here/../web/public/cards/$id.webp" work="$here/grok-work/$id" style="Style: tabletop board-game card illustration, miniature diorama look with tilt-shift depth of field, soft isometric three-quarter top-down view, warm gouache texture, clean readable shapes, cohesive warm palette with a few saturated accents. Setting: present-day Taiwan. Absolutely no text, no letters, no numbers, no logos, no party symbols or party colors on flags (flags and banners are plain), no real or recognizable people; all figures are small, anonymous and stylized. Square image." if [[ ! -s "$out" ]]; then mkdir -p "$work" marker="$work/.start" : > "$marker" grok -p "Use your image generation tool to create exactly ONE image. Subject: $subject. $style Do not run any shell commands and do not edit files; just generate the image and reply with the word done." \ --cwd "$work" --allow imagine --max-turns 4 > "$here/generated/$id.log" 2>&1 img=$(find "$HOME/.grok/sessions" -path "*grok-work%2F$id*" -newer "$marker" -type f \( -name "*.jpg" -o -name "*.png" -o -name "*.webp" \) 2>/dev/null | head -1) if [[ -n "$img" ]]; then ffmpeg -loglevel error -y -i "$img" "$out" fi fi if [[ -s "$out" ]]; then cwebp -quiet -q 80 -resize 640 640 "$out" -o "$web" && echo "ok $id" else echo "FAIL $id" fi