Gemini Image Generation & Editing

VerifiedCaution

Generate, edit, and iteratively modify images using the Gemini API, with support for high-resolution output and multi-turn conversations.

Sby Skills Guide Bot
ContentIntermediate
7/24/2026
Claude Code
#image-generation#image-editing#gemini-api#text-to-image#multi-turn

Recommended for

Automated summary

Generates and edits images through the Gemini API (Nano Banana models) using a Python script, supporting text-to-image, image editing, and iterative multi-turn refinement sessions.

Strengths

  • Covers generation, editing, and multi-turn refinement from one script with simple subcommands
  • Automatically switches to the pro model for 2K/4K output and handles common aspect ratios
  • Defines a clear workflow that has the agent read back every generated image for the user
  • Accepts both Chinese and English prompts

Limitations

  • Requires a GEMINI_API_KEY, the google-genai and Pillow packages, and possibly a proxy
  • Chat sessions live in a local .pkl file with no sharing or versioning
  • Long generation times demand extended Bash timeouts (~120 s) and complex prompts may fail
When to use it

Use when a user wants to create an image, modify an existing one, or iterate on a visual through successive edits from Claude Code.

When not to use it

Avoid when no Gemini API key is configured or when the environment cannot run Python scripts with network access.

Security analysis

Caution
Quality score86/100

The skill is not overtly malicious: it does not instruct destructive commands, credential exfiltration, obfuscation, or safety bypass. However, it uses Bash, network access, environment-stored API keys, file writes, and package installation for a legitimate image-generation workflow, so it warrants caution rather than safe.

Findings
  • •Uses Bash to execute a Python script that performs network requests to the Gemini API and writes image files.
  • •Requires access to GEMINI_API_KEY from the environment; the skill itself does not exfiltrate it, but the script is not included for inspection.
  • •Mentions optional pip3 install of dependencies, which executes package installation commands.
  • •Relies on an external script at ~/.claude/skills/gemini-image/scripts/gemini_image.py whose behavior cannot be verified from SKILL.md alone.
How this analysis is made

Examples

Text-to-image with aspect ratio
Generate a 16:9 illustration of a misty mountain lake at sunrise, minimal flat style, muted blues and oranges, saved as lake.png
Iterative editing session
Start a chat session to create a product shot of a white ceramic mug on a wooden table, then change the background to a beach and make the lighting warmer
Upscale to 2K
把这张图片重绘为 2K 高清版本,保留原有构图和颜色,输出到 hd.png

name: gemini-image description: | 使用 Gemini API 生成和编辑图片。当用户要求生成图片、编辑图片、修改图片、重绘图片、 生成高清图片、多轮对话迭代修改图片时触发此技能。 关键词: 生成图片、画图、图片编辑、修图、重绘、高清、2K、4K、text-to-image、image editing allowed-tools: Read, Write, Edit, Bash, Glob, Grep, AskUserQuestion

Gemini 图片生成与编辑技能

通过 Gemini API (Nano Banana 系列模型) 为用户生成、编辑、迭代修改图片。

工具脚本

SCRIPT="$HOME/.claude/skills/gemini-image/scripts/gemini_image.py"

所有图片操作通过此脚本完成,运行方式:

python3 "$SCRIPT" <command> [args...]

环境要求

  • API Key: 存在环境变量 $GEMINI_API_KEY (用户已配置在 .zshrc)
  • 代理: 如需代理,用户应在 shell 中设置 http_proxy 和 https_proxy 环境变量
  • 依赖: google-genai, Pillow (如未安装则运行: pip3 install google-genai Pillow)

模型选择

| 模型 ID | 别名 | 特点 | |---------|------|------| | gemini-3.1-flash-image-preview | flash | 快速,日常生成/编辑,默认选择 | | gemini-3-pro-image-preview | pro | 高质量,支持 2K/4K 分辨率输出 |

  • 默认使用 flash 模型
  • 当用户要求 2K/4K 高清时,自动切换到 pro 模型

命令参考

1. 文本生成图片

python3 "$SCRIPT" generate "描述文字" --output result.png --ratio 16:9 --model flash

参数:

  • prompt: 图片描述 (必填)
  • --output: 输出文件路径 (默认 generated.png)
  • --ratio: 宽高比,可选 1:1 2:3 3:2 3:4 4:3 4:5 5:4 9:16 16:9 21:9
  • --size: 分辨率 2k 或 4k (指定后自动使用 pro 模型)
  • --model: flash(默认) 或 pro

2. 编辑已有图片

python3 "$SCRIPT" edit "编辑指令" --input source.png --output edited.png

参数:

  • prompt: 编辑指令 (必填,如 "把背景换成海边"、"去掉水印"、"重绘为高清版本")
  • --input: 输入图片路径 (必填)
  • --output: 输出文件路径 (默认 edited.png)
  • --ratio, --size, --model: 同上

3. 多轮对话 - 创建新会话

python3 "$SCRIPT" chat_new --session .gemini_chat_session.pkl

4. 多轮对话 - 发送消息

python3 "$SCRIPT" chat_send "修改指令" --session .gemini_chat_session.pkl --output v2.png
python3 "$SCRIPT" chat_send "继续修改" --input another.png --session .gemini_chat_session.pkl --output v3.png

参数:

  • prompt: 文字指令 (必填)
  • --session: 会话文件 (默认 .gemini_chat_session.pkl,不存在则自动创建)
  • --input: 可选,附带一张图片
  • --output: 输出文件路径 (默认 chat_output.png)

工作流程

场景 A: 单次生成/编辑

  1. 根据用户需求确定命令 (generate 或 edit)
  2. 选择合适的参数 (ratio, size, model)
  3. 运行脚本,等待生成
  4. 用 Read 工具查看生成的图片,向用户展示
  5. 如果用户不满意,根据反馈调整 prompt 重新生成

场景 B: 多轮迭代修改 (推荐用于需要反复调整的场景)

  1. 创建会话或直接发送第一条消息 (chat_send 会自动创建会话)
  2. 运行 chat_send,生成第一版图片
  3. 用 Read 工具查看图片,向用户展示
  4. 用户提出修改意见
  5. 继续用 chat_send 发送修改指令 (模型会记住上下文,无需重新描述)
  6. 重复 3-5 直到用户满意
  7. 如果用户最终想要高清版本,用 edit 命令 + --size 2k/4k 对最终版进行高清化

场景 C: 高清重绘已有图片

  1. 用 Read 工具先查看原图,理解内容
  2. 撰写详细的重绘 prompt (描述图片中的所有元素、布局、颜色)
  3. 运行 edit 命令,传入原图 + prompt + --size 2k
  4. 查看结果,向用户展示

重要提示

  • 每次生成图片后,必须用 Read 工具读取并展示给用户,这样用户才能看到效果
  • 生成图片的 prompt 要尽量具体详细,描述清楚风格、颜色、布局、内容
  • 多轮对话中,模型记住了之前的图片,所以后续指令可以简短 (如 "把颜色改成蓝色")
  • 如果生成失败 (finish_reason 不是 STOP),尝试简化 prompt 后重试
  • 中文和英文 prompt 都支持,复杂场景建议用英文 prompt 效果更好
  • 超时设置: 图片生成可能需要较长时间,Bash 命令 timeout 建议设为 120000ms

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/gemini-image-generation-editing-mryiqg2f/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/gemini-image-generation-editing-mryiqg2f' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/gemini-image-generation-editing-mryiqg2f/download' --output '.skill-downloads/gemini-image-generation-editing-mryiqg2f/SKILL.md.part' && mv '.skill-downloads/gemini-image-generation-editing-mryiqg2f/SKILL.md.part' '.skill-downloads/gemini-image-generation-editing-mryiqg2f/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

Tools declared by the author (check availability in your agent): Read, Write, Edit, Bash, Glob, Grep, AskUserQuestion

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/gemini-image-generation-editing-mryiqg2f/SKILL.md' && test -s '.skill-downloads/gemini-image-generation-editing-mryiqg2f/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/gemini-image' && cp -R '.skill-downloads/gemini-image-generation-editing-mryiqg2f' '.claude/skills/gemini-image'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/gemini-image-generation-editing-mryiqg2f'

openskills read 'gemini-image-generation-editing-mryiqg2f'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/gemini-image-generation-editing-mryiqg2f/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills