ClawSkills logoClawSkills

Gemini Image Simple

使用纯 Python 标准库通过 Gemini API 生成和编辑图像。零依赖——在不可用 pip/uv 的受限环境中工作。

介绍

# Gemini Image Simple

使用 Google 的 **Nano Banana Pro** (Gemini 3 Pro Image) 生成和编辑图像——这是最高质量的图像生成模型。

## 为什么选择此技能

| 特性 | 此技能 | 其他 (nano-banana-pro 等) | |---------|------------|-------------------------------| | **依赖项** | 无(仅标准库) | google-genai, pillow 等 | | **需要 pip/uv** | ❌ 不需要 | ✅ 需要 | | **在 Fly.io 免费版上可用** | ✅ 可用 | ❌ 失败 | | **在容器中可用** | ✅ 可用 | ❌ 经常失败 | | **图像生成** | ✅ 完整 | ✅ 完整 | | **图像编辑** | ✅ 支持 | ✅ 支持 | | **设置复杂度** | 仅需设置 API 密钥 | 需先安装软件包 |

**总结:** 此技能可以在任何存在 Python 3 的地方运行。无需包管理器,无需虚拟环境,无权限问题。

## 快速开始

```bash # Generate python3 /data/clawd/skills/gemini-image-simple/scripts/generate.py "A cat wearing a tiny hat" cat.png

# Edit existing image python3 /data/clawd/skills/gemini-image-simple/scripts/generate.py "Make it sunset lighting" edited.png --input original.png ```

## 用法

### 生成新图像

```bash python3 {baseDir}/scripts/generate.py "your prompt" output.png ```

### 编辑现有图像

```bash python3 {baseDir}/scripts/generate.py "edit instructions" output.png --input source.png ```

支持的输入格式:PNG, JPG, JPEG, GIF, WEBP

## 环境变量

设置 `GEMINI_API_KEY` 环境变量。在 https://aistudio.google.com/apikey 获取。

## 工作原理

使用 **Nano Banana Pro** (`nano-banana-pro-preview`)——Google 最高质量的图像生成模型: - 纯 `urllib.request` 用于 HTTP(无需 requests 库) - 纯 `json` 用于解析(标准库) - 纯 `base64` 用于编码(标准库)

仅此而已。没有外部软件包。适用于任何 Python 3.10+ 安装环境。

## 模型

当前使用:`nano-banana-pro-preview` (也称为 Gemini 3 Pro Image)

其他可用模型(如有需要可在 generate.py 中更改): - `gemini-3-pro-image-preview` - 与 Nano Banana Pro 相同 - `imagen-4.0-ultra-generate-001` - Imagen 4.0 Ultra - `imagen-4.0-generate-001` - Imagen 4.0 - `gemini-2.5-flash-image` - 具有图像生成功能的 Gemini 2.5 Flash

## 示例

```bash # Landscape python3 {baseDir}/scripts/generate.py "Misty mountains at sunrise, photorealistic" mountains.png

# Product shot python3 {baseDir}/scripts/generate.py "Minimalist product photo of a coffee cup, white background" coffee.png

# Edit: change style python3 {baseDir}/scripts/generate.py "Convert to watercolor painting style" watercolor.png --input photo.jpg

# Edit: add element python3 {baseDir}/scripts/generate.py "Add a rainbow in the sky" rainbow.png --input landscape.png ```

更多产品