arnavpuri/designskills

image-generation

Foundational skill for AI-powered image generation using Gemini 3.1 Flash Image Preview.

查看源码

使用方法

  1. 复制安装命令,在自己的智能体环境安装前先检查源码包。
  2. 从原始文档核对所需工具、凭据和支持的宿主。
  3. 说明输入材料与期望交付物,并对照来源检查输出。
npx skills add https://github.com/arnavpuri/designskills --skill image-generation

开始前需了解

  • 安装不包含模型订阅、API 额度或访问文件的权限。
  • 仓库星数和安装量反映活跃情况,不等于独立质量或安全测试。
仓库原始内容

按源仓库内容呈现,保留标题、案例、代码、表格、链接以及原文引用的演示图片。

Image Generation with Gemini 3.1 Flash

Foundational skill for generating and editing images using Google's Gemini 3.1 Flash Image Preview model. All graphic design skills reference this skill for the generation pipeline.


Prerequisites

bash
pip install google-genai Pillow
export GEMINI_API_KEY="your-api-key"

Step 0: Load Brand Context

Read .agents/design-context.md if it exists and pull the hex colors, style archetype, and typography description into the prompt. If it doesn't exist, use the design-context defaults and tell the user the output isn't brand-matched yet. If the user has a logo or product photo, pass it as an --image reference rather than describing it — the model reproduces references far more faithfully than descriptions.


Step 1: Choose Generation Mode

ModeWhen to UseInput
Text-to-ImageCreating from scratch — posters, graphics, illustrationsText prompt only
Image EditProduct shots, mockups, style transfer, adding elementsImage + text prompt
Multi-TurnIterative refinement, exploring variationsChat session
BatchHigh-volume asset generation (social sets, ad variants)Multiple prompts via Batch API

Step 2: Build the Prompt

Prompt Structure

Every prompt should follow this hierarchy:

[FORMAT] + [SUBJECT] + [STYLE] + [COMPOSITION] + [COLOR] + [TYPOGRAPHY] + [MOOD] + [NEGATIVE]

Example — product social post:

Create a square social media graphic for a premium headphone launch. The headphones are centered on a deep navy (#0d1b2a) to electric blue (#00b4d8) diagonal gradient background. Bold white sans-serif text "HEAR EVERYTHING" spans the top third. Small coral (#ff6b6b) subtext "Available March 20" below. Subtle geometric triangles in the background at 10% opacity. Clean, modern, premium feel. No borders, no clip art.

Key Principles

  1. Describe scenes, not keywords — "A sneaker floating above a reflective surface with dramatic side lighting" beats "sneaker, cool, modern"
  2. Be specific about colors — Always include hex codes from design context
  3. Describe spatial layout — "headline in upper third, product centered, CTA in lower right"
  4. Name the style — "flat vector", "3D render", "watercolor", "photorealistic", "minimalist Swiss design"
  5. Include typography instructions — font style, size relationship, color, position
  6. State what to exclude — "no stock photo watermarks, no beveled effects, no clipart"

Style-Specific Prompt Patterns

StylePrompt Additions
Minimalist"generous whitespace, single accent color, clean sans-serif, no decorative elements"
Bold/Vibrant"saturated colors, large impactful typography, geometric shapes, high contrast"
Luxurious"dark background, gold or champagne accents, serif typography, subtle texture, elegant"
Playful"bright palette, rounded shapes, hand-drawn feel, casual handwriting font"
Corporate"structured grid, professional, blue tones, clean hierarchy, balanced composition"
Retro"halftone dots, muted vintage palette, serif headlines, film grain texture"
Brutalist"raw, high contrast black and white, unconventional layout, oversized type"

Step 3: Generate

Text-to-Image

python
from google import genai
from google.genai import types

client = genai.Client()

response = client.models.generate_content(
    model="gemini-3.1-flash-image-preview",
    contents="[your structured prompt]",
    config=types.GenerateContentConfig(
        response_modalities=["TEXT", "IMAGE"],
        image_config=types.ImageConfig(aspect_ratio="1:1", image_size="2K"),
    ),
)

# A response can contain text parts and image parts in any order —
# never assume parts[0] is the image.
def save_first_image(response, path):
    for part in response.parts or []:
        if part.inline_data is not None:
            part.as_image().save(path)
            return True
    print("No image returned:", response.text)  # usually a refusal or clarifying question
    return False

save_first_image(response, "output.png")

Image Editing (Product Image → Graphic)

The core workflow: user provides a product photo, you generate a complete graphic around it.

python
from PIL import Image

product = Image.open("product.png")

response = client.models.generate_content(
    model="gemini-3.1-flash-image-preview",
    contents=[
        product,
        "Transform this product photo into a premium social media graphic. "
        "Place the product on a gradient background (#1a1a2e to #16213e). "
        "Add bold white headline 'JUST DROPPED' above. "
        "Add price '$299' in coral (#e94560) below. "
        "Modern, clean, high-end feel. Square format."
    ],
    config=types.GenerateContentConfig(
        response_modalities=["TEXT", "IMAGE"],
    ),
)

Multi-Turn Refinement

python
chat = client.chats.create(
    model="gemini-3.1-flash-image-preview",
    config=types.GenerateContentConfig(response_modalities=["TEXT", "IMAGE"]),
)

# Generate
r1 = chat.send_message([product_image, "Create a launch graphic for this product..."])
save_first_image(r1, "v1.png")

# Refine colors — change ONE thing per turn and say what to keep
r2 = chat.send_message("Keep the layout and text exactly as is. Make the background warmer, shift to sunset tones")
save_first_image(r2, "v2.png")

# Refine text
r3 = chat.send_message("Keep everything else. Make the headline larger and add a subtle drop shadow")
save_first_image(r3, "v3.png")

CLI Tool

The skill ships its scripts in scripts/. Below, <image-generation> means this skill's directory (the base directory shown when the skill loads; skills/image-generation in a clone of the repo). Run them from the user's project so outputs land there.

bash
# Text-to-image
python <image-generation>/scripts/gemini-generate.py --prompt "..." --output graphic.png

# Product image + prompt
python <image-generation>/scripts/gemini-generate.py --image product.png --prompt "..." --output graphic.png

# Multiple reference images (product + logo + style reference), up to 14
python <image-generation>/scripts/gemini-generate.py --image product.png --image logo.png --prompt "..." --output graphic.png

# Aspect ratio and resolution
python <image-generation>/scripts/gemini-generate.py --prompt "..." --aspect-ratio 4:5 --size 2K --output feed.png

# Exact pixel size: generate at the nearest supported ratio, then center-crop + resize
python <image-generation>/scripts/gemini-generate.py --prompt "..." --aspect-ratio 8:1 --resize 728x90 --output leaderboard.png

# Long prompts: keep them in a file
python <image-generation>/scripts/gemini-generate.py --prompt-file prompt.txt --aspect-ratio 16:9 --output hero.png

# Multi-turn (--then is repeatable; outputs default to v1_2.png, v1_3.png ...)
python <image-generation>/scripts/gemini-generate.py --prompt "Create a poster..." --output v1.png \
    --then "Change to dark mode" --then "Make the date larger"

The script exits non-zero when no image comes back (refusal, safety block, or the model answered with text only) and prints the model's text — read it, adjust the prompt, and retry.

Exporting Many Sizes From One Master

bash
# Social set, ad set, or named presets; --focus keeps the subject in frame (x,y as 0-1)
python <image-generation>/scripts/export-sizes.py master.png --group social --out exports/
python <image-generation>/scripts/export-sizes.py master.png --presets og,youtube-thumbnail --focus 0.5,0.4 --out exports/
python <image-generation>/scripts/export-sizes.py master.png --size 300x250 --size 728x90 --out ads/
python <image-generation>/scripts/export-sizes.py --list   # all presets and groups

It warns when a crop keeps under half of the master or has to upscale -- generate extreme ratios (8:1, 1:4) separately with the matching --aspect-ratio instead. Read a few exports to confirm nothing important was cropped.


Step 4: Aspect Ratios

Supported ratios: 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9, 1:4, 4:1, 1:8, 8:1. Anything else (e.g. 300x250, 1200x628) must be generated at the nearest ratio and cropped with --resize.

Use CaseRatioFinal sizeNotes
Instagram feed (portrait)4:51080x1350Best feed real estate; grid preview crops to 3:4 center
Instagram feed (square)1:11080x1080Keep text ~100px from edges
Instagram / TikTok Story, Reels9:161080x1920Keep text out of top ~250px and bottom ~340px (UI overlays)
X / Twitter post16:91600x900Text readable at small preview size
LinkedIn post1:1 or 4:51200x1200 / 1080x1350Link previews are ~1.91:1 (1200x627) — generate 16:9 + --resize
Facebook / Open Graph link image16:9 → crop1200x630Generate 16:9, --resize 1200x630
Pinterest pin2:31000x1500Vertical, scroll-stopping
YouTube thumbnail16:91280x720High contrast, readable at 168x94px; avoid bottom-right (timestamp)
Web banner (leaderboard)8:1728x90Minimal text, strong CTA
Medium rectangle ad5:4 → crop300x250--resize 300x250
Poster / flyer2:3 or 3:4print sizeSee poster-design for bleed and DPI; 4K for print

Step 5: Look at the Output, Then Check It

Never deliver an image you haven't viewed. Open every generated file (e.g. with the Read tool on the PNG) and inspect it at full size and at the size it will actually be seen (a thumbnail, a feed card).

Getting text right

Text is the most common failure. To reduce errors:

  • Put exact copy in double quotes in the prompt: headline "HEAR EVERYTHING"
  • Keep rendered text short — a headline, a subline, a CTA. Move long copy (paragraphs, legal, prices that change) into an HTML/CSS overlay instead of the image.
  • Spell out unusual words or brand names and say "spelled exactly as written".
  • If a word comes back misspelled, fix it in a follow-up turn quoting only that word: Change "EVERYTHNG" to "EVERYTHING". Change nothing else.
  • After two failed text fixes, generate the image without text and add the text as a code overlay (see graphic-design).

Before delivering any generated image:

  • [ ] Text is legible and spelled correctly (Gemini can render text — verify it)
  • [ ] Colors match brand context (hex codes specified in prompt)
  • [ ] Composition has clear visual hierarchy (one focal point)
  • [ ] Sufficient contrast between text and background
  • [ ] No unwanted artifacts or distortions
  • [ ] Aspect ratio matches intended platform
  • [ ] Product image (if used) is cleanly integrated, not distorted
  • [ ] Overall aesthetic matches the requested style

If any check fails, use multi-turn refinement to fix specific issues — one change per turn, and say what must stay the same. Report to the user which checks you verified and any compromises (e.g. "text added as overlay because the model kept misspelling it").

Also mention that Gemini output carries an invisible SynthID watermark, so it can be identified as AI-generated.


Reference: Model Capabilities

FeatureGemini 3.1 Flash
Max input images14 (10 objects + 4 characters)
Output resolutions512, 1K, 2K, 4K
Aspect ratios1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9, 1:4, 4:1, 1:8, 8:1
Text renderingSupported (specify explicitly in prompt)
Thinking modeOn by default, improves complex compositions
Batch APISupported for high-volume generation
WatermarkSynthID automatically applied

Integration with Other Skills

This skill is referenced by all graphic design skills:

  • graphic-design → primary generation pipeline
  • social-media-graphic → platform-specific generation
  • poster-design → poster/flyer generation
  • thumbnail-design → thumbnail generation
  • ad-creative-design → ad variant generation
  • product-mockup → product shot generation
  • banner-design → banner generation
  • infographic → infographic generation

Each skill adds domain-specific prompt patterns on top of this foundational generation workflow.

按任务相关推荐

来自同一仓库

更多 Skills

全部 Skills
arnavpuri
社区

banner-design

Banner graphics for owned channels: website hero/section banner images, email header images, event and conference banners, sidebar house promos, and announcement bars, via Gemini 3.1 Flash image generation (default) or HTML/CSS. Covers standard sizes, Gemini ratios and cropping, CTA placement, responsive art direction, and email constraints. For paid display/IAB ads use ad-creative-design; for a coded above-the-fold section use hero-section; for a full email template use email-design. Trigger ph

安装量
1
GitHub Stars
10
最近更新
9月28日
arnavpuri
社区

design-context

Foundational design context skill. Establishes brand identity, color system, typography, design style, and audience preferences, saved to .agents/design-context.md for every other design skill to reuse. Trigger phrases: "set up design context", "define brand style", "style guide setup", "initialize design", "set brand colors", "use our brand". To build a full token system and components use design-system; to generate a palette use color-palette; to create a logo and identity use brand-identity.

安装量
1
GitHub Stars
10
最近更新
9月28日
arnavpuri
社区

design-critique

Critique an existing design (web page, HTML/React UI, screenshot, generated image, or Figma frame) with a repeatable procedure: capture it (Playwright screenshots or Read for images), run automated checks (axe, style inventory), score against a weighted rubric, and output severity-ranked fixes with code, then re-verify. Use after any design is produced or when asked to review one. Trigger phrases: "design critique", "review design", "improve design", "design audit", "design feedback", "evaluate

安装量
1
GitHub Stars
10
最近更新
9月28日
arnavpuri
社区

image-treatment

Treat existing images in code: CSS filters, blend modes, duotone, masks and clip-paths, overlays for text legibility, collages, SVG filters, and responsive delivery (picture/srcset/sizes, AVIF/WebP). Use when styling or serving photos on a page; to CREATE new images use image-generation. Trigger phrases: "image effect", "photo filter", "image overlay", "duotone", "image mask", "parallax background", "clip-path", "blend mode", "image grid", "responsive image", "css filter"

安装量
1
GitHub Stars
10
最近更新
9月28日