Programmatic AI Image Generation
Model pricing/selection is governed by the
model-packageskill: drafts/batch use the default tier (z-image-turbo0.10 RMB/image), covers/final pieces use the quality tier (qwen-image-3.0-pro2K 0.50 RMB/image). This skill only describes the invocation method; prices and IDs are not maintained here.
Practical experience from novel promotion video production, as of 2026-08-31. When the built-in
image_generatetool is unavailable or requires batch/precise control, use the SiliconFlow image generation API.
Channel Priority
- Qwen Cloud Image Generation (Model Package ③: default
qwen-image-3.00.18/image, cover quality tierqwen-image-3.0-pro2k; this channel has historically run wan2.6-t2i, endpoint/parameter differences are in call-recipes): Outputs native 1152x1536/1152x1152 images, then scaled to platform specifications; submit batches in waves, retry with backoff on 429/RateQuota (1-4 concurrent is safe, 8 concurrent will trigger limits; image models do not use Batch inference, only async tasks + retries). - Built-in
image_generate(dashscope/wan2.7 channel) — try first; but may return 401 Unauthorized - TokenPlan Tongyi Wanxiang (see token-plan-image-gen skill, 1-2 tokens per image, weekly quota)
- SiliconFlow Qwen-Image API (¥0.3/image; ⚠️ As of 2026-09-08, the test key shows no balance [30001], recharge/restore before use)
⚠️ 2026-09-08 Update: Both the SiliconFlow paid key and free key have no balance (30001 balance insufficient), the "fallback to SiliconFlow Qwen-Image" alternative is currently unavailable. For image generation, prioritize TokenPlan Wanxiang; switch back when SiliconFlow balance is restored.
Quick SiliconFlow Qwen-Image Invocation
- Endpoint: POST
https://api.siliconflow.cn/v1/images/generations(not /chat/completions) - Header:
Authorization: Bearer <SILICONFLOW_API_KEY>(available in default .env) - Body:
{"model":"Qwen/Qwen-Image","prompt":"...","image_size":"768x1344","batch_size":1,"num_inference_steps":20,"guidance_scale":3.0} - Response:
images[0].url= an S3 temporary URL, download immediately (it will expire) - Full code and pitfalls in
references/siliconflow-image-gen.md
Dimension Presets
- Vertical 9:16 (Douyin/novel cover):
768x1344 - Square 1:1 (avatar/book cover):
1024x1024 - Horizontal 16:9:
1344x768
Cover Recipe (Fanqie 750x1000, tested 2026-09-01)
- Fanqie book cover = 3:4 vertical 750x1000; generate with Qwen-Image at 768x1344 → scale by max(750/w, 1000/h) → crop center 750x1000
- ⚠️ Dark-themed AI images are often too dark (dark area <40 accounts for >50%): the small cover image must be brightened — apply gamma**(1/1.35) clip + Contrast 1.06, reduce dark area to ~45% before delivery, otherwise it will be illegible at small size
- Overlay the title with PIL: msyhbd.ttc (Microsoft YaHei Bold) 72px two lines + bottom label 40px; draw semi-transparent black bars (alpha 160) at top/bottom to ensure text readability
- Save as cover.jpg quality=92; original 768x1344 stored as source\cover_raw*.png, only cover.jpg remains in the root directory
- Full implementation reference: <WORK_DIR>\Tools\Scripts\Novel\cover_jujitsu.py
Cover-Fill Crop (→ 1080x1920)
scale = max(1080/w, 1920/h)
img = img.resize((int(w*scale), int(h*scale)), Image.LANCZOS)
img = img.crop((x, y, x+1080, y+1920))
Overseas Premium Cover Battle Standards (Cover regulations: no token sparing, quality first)
- Both brightness metrics must be reported simultaneously: list both mean gray value and dark area (gray<40) percentage — "mean≤55" and "dark area≤55%" are two different judgment criteria; delivering only one metric will invite follow-up questions. Deliver both bright and dark versions; when remapping dark tones (gamma darkening), keep the title as bright white text.
- Qwen wan2.6-t2i image generation: the negative prompt must include
no glyphs, no letters on screens, dust particles, melted foliage; all text must be added via PIL overlay, never in the model (Georgia Bold/Bookman Old Style Bold + Segoe UI Bold); scale the final image's long side to platform specifications (KDP vertical 1600x2560=1:1.6 official recommended ratio, square 2560x2560, SH series pages 1600x2400=2:3). - VLM self-check runs 3 votes, majority wins: check text legibility/smear/dust/melting/over-darkness — each item reports True/False; if 1/3 votes deem map fine text as "smear" (a common false positive), while the other 2 votes judge it as natural depth of field and semantically reasonable, let it pass and record the dissenting vote truthfully — do not reject a whole batch due to a single dissenting vote. Perform OCR on the book title to verify spelling.
- Each final piece must include a 154px thumbnail and verify the book title is legible on the thumbnail (thumbnail impact is the life-or-death factor for click-through rates; long titles should use two-line layout).
- MANIFEST.txt lists each image: dimensions/ratio/mean gray/std/dark area percentage/thumbnail std/file size (MB)/source image provenance/digital processing record/VLM readings/recommended usage/untouched asset list/boundary declaration (not uploaded/payload untouched)/reproducible script location.
- GM acceptance = independent recalculation, not relying on the manifest: one
execute_codecall uses PIL to reopen each final piece, recalculate mean/dark area percentage, and compare against the MANIFEST values (should match to the decimal point); glob to verify thumbnails exist; any discrepancy results in rejection.
Cover "AI Base + PIL Text Overlay" Hybrid Route (Default)
- Division of labor is fixed: the base image is strictly AI-generated (atmosphere/composition is where it excels), all text and marks are composited by PIL; when replacing the base image, do not revert to older font sizes/mark intensities — text overlay intensity must always be at the highest historical level; thumbnail legibility is the life-or-death factor for click-through.
- Judgments (must be based on disk file pixels measured by QA script, never use self-reported intended values from the generation script): headline capital letter height in 200px thumbnail ≥15px (premium 17px); contrast between headline and adjacent background ≥15:1; mark/seal contrast ≥3:1 (graphic threshold); marks must not intrude into the signature zone (pixel count of mark-colored pixels inside the signature box must be 0, write as a hard criterion); human face count 0 (YuNet 0.4+0.15 dual threshold); base image MSER false text blobs 0; dimensions exactly three tiers (1600×2560 primary / 800×1200 / 200×320).
- Enlarged marks must be checked for overlap: enlarged mark diameter = lower edge moves down, first shift the stamp center upward then visually inspect, and encode the overlap check as a script hard criterion, not manual inspection.
- Deliver three pieces in one package: three-tier PNG + QA report markdown + generation script and base image (if the script and base image are not in the package, it is not reproducible, equivalent to no delivery).
- Reference implementation (including all constants and hard criteria):
<WORK_DIR>\Writing\_Overseas Operations\New Book B-Publish Package-20261021\Covers\v3\make_B_cover_v3.py+qa_B_cover_v3.py.
Common Pitfalls
- Prompt is more stable in English; append "No text, no watermark" at the end
- Synchronous response takes about 26s/image; add
time.sleep(1)between batches to avoid rate limiting cv2.imwritefails with Chinese file paths; useimencode+buf.tofile; PILsaveworks with Chinese paths