agentleFS
Sign inSign up

generate-image

LeonChaoX/qinyan-academic-skills/skills/03-学术演示与可视化/generate-image/SKILL.md

Generate or edit images using AI models (FLUX, Nano Banana 2). Use for general-purpose image generation including photos, illustrations, artwork, visual assets, concept art, and any image that is not a technical diagram or schematic. For flowcharts, circuits, pathways, and technical diagrams, use the scientific-schematics skill instead.

Skill910 starsChanged 7 months ago
  • Reads credentials

What's in it

  1. Generate Image
  2. When to Use This Skill
  3. Quick Start
  4. API Key Setup
  5. Model Selection
  6. Common Usage Patterns
  7. Basic generation
  8. Specify model
  9. Custom output path
  10. Edit an existing image
  11. Edit with a specific model
  12. Edit with custom output
  13. Multiple images
  14. Script Parameters
  15. Example Use Cases
  16. For Scientific Documents
  17. For Presentations and Posters
  18. For General Visual Content
  19. Error Handling
  20. Notes
  21. Image Editing Tips
  22. Integration with Other Skills
---
name: generate-image
description: Generate or edit images using AI models (FLUX, Nano Banana 2). Use for general-purpose image generation including photos, illustrations, artwork, visual assets, concept art, and any image that is not a technical diagram or schematic. For flowcharts, circuits, pathways, and technical diagrams, use the scientific-schematics skill instead.
license: MIT license
compatibility: Requires an OpenRouter API key
metadata:
    skill-author: K-Dense Inc.
---

# Generate Image

Generate and edit high-quality images using OpenRouter's image generation models including FLUX.2 Pro and Gemini 3.1 Flash Image Preview.

## When to Use This Skill

**Use generate-image for:**
- Photos and photorealistic images
- Artistic illustrations and artwork
- Concept art and visual concepts
- Visual assets for presentations or documents
- Image editing and modifications
- Any general-purpose image generation needs

**Use scientific-schematics instead for:**
- Flowcharts and process diagrams
- Circuit diagrams and electrical schematics
- Biological pathways and signaling cascades
- System architecture diagrams
- CONSORT diagrams and methodology flowcharts
- Any technical/schematic diagrams

## Quick Start

Use the `scripts/generate_image.py` script to generate or edit images:

```bash
# Generate a new image
python scripts/generate_image.py "A beautiful sunset over mountains"

# Edit an existing image
python scripts/generate_image.py "Make the sky purple" --input photo.jpg
```

This generates/edits an image and saves it as `generated_image.png` in the current directory.

## API Key Setup

**CRITICAL**: The script requires an OpenRouter API key. Before running, check if the user has configured their API key:

1. Look for a `.env` file in the project directory or parent directories
2. Check for `OPENROUTER_API_KEY=<key>` in the `.env` file
3. If not found, inform the user they need to:
   - Create a `.env` file with `OPENROUTER_API_KEY=your-api-key-here`
   - Or set the environment variable: `export OPENROUTER_API_KEY=your-api-key-here`
   - Get an API key from: https://openrouter.ai/keys

The script will automatically detect the `.env` file and provide clear error messages if the API key is missing.

## Model Selection

**Default model**: `google/gemini-3.1-flash-image-preview` (high quality, recommended)

**Available models for generation and editing**:
- `google/gemini-3.1-flash-image-preview` - High quality, supports generation + editing
- `black-forest-labs/flux.2-pro` - Fast, high quality, supports generation + editing

**Generation only**:
- `black-forest-labs/flux.2-flex` - Fast and cheap, but not as high quality as pro

Select based on:
- **Quality**: Use gemini-3.1-flash-image-preview or flux.2-pro
- **Editing**: Use gemini-3.1-flash-image-preview or flux.2-pro (both support image editing)
- **Cost**: Use flux.2-flex for generation only

## Common Usage Patterns

### Basic generation
```bash
python scripts/generate_image.py "Your prompt here"
```

### Specify model
```bash
python scripts/generate_image.py "A cat in space" --model "black-forest-labs/flux.2-pro"
```

### Custom output path
```bash
python scripts/generate_image.py "Abstract art" --output artwork.png
```

### Edit an existing image
```bash
python scripts/generate_image.py "Make the background blue" --input photo.jpg
```

### Edit with a specific model
```bash
python scripts/generate_image.py "Add sunglasses to the person" --input portrait.png --model "black-forest-labs/flux.2-pro"
```

### Edit with custom output
```bash
python scripts/generate_image.py "Remove the text from the image" --input screenshot.png --output cleaned.png
```

### Multiple images
Run the script multiple times with different prompts or output paths:
```bash
python scripts/generate_image.py "Image 1 description" --output image1.png
python scripts/generate_image.py "Image 2 description" --output image2.png
```

## Script Parameters

- `prompt` (required): Text description of the image to generate, or editing instructions
- `--input` or `-i`: Input image path for editing (enables edit mode)
- `--model` or `-m`: OpenRouter model ID (default: google/gemini-3.1-flash-image-preview)
- `--output` or `-o`: Output file path (default: generated_image.png)
- `--api-key`: OpenRouter API key (overrides .env file)

## Example Use Cases

### For Scientific Documents
```bash
# Generate a conceptual illustration for a paper
python scripts/generate_image.py "Microscopic view of cancer cells being attacked by immunotherapy agents, scientific illustration style" --output figures/immunotherapy_concept.png

# Create a visual for a presentation
python scripts/generate_image.py "DNA double helix structure with highlighted mutation site, modern scientific visualization" --output slides/dna_mutation.png
```

### For Presentations and Posters
```bash
# Title slide background
python scripts/generate_image.py "Abstract blue and white background with subtle molecular patterns, professional presentation style" --output slides/background.png

# Poster hero image
python scripts/generate_image.py "Laboratory setting with modern equipment, photorealistic, well-lit" --output poster/hero.png
```

### For General Visual Content
```bash
# Website or documentation images
python scripts/generate_image.py "Professional team collaboration around a digital whiteboard, modern office" --output docs/team_collaboration.png

# Marketing materials
python scripts/generate_image.py "Futuristic AI brain concept with glowing neural networks" --output marketing/ai_concept.png
```

## Error Handling

The script provides clear error messages for:
- Missing API key (with setup instructions)
- API errors (with status codes)
- Unexpected response formats
- Missing dependencies (requests library)

If the script fails, read the error message and address the issue before retrying.

## Notes

- Images are returned as base64-encoded data URLs and automatically saved as PNG files
- The script supports both `images` and `content` response formats from different OpenRouter models
- Generation time varies by model (typically 5-30 seconds)
- For image editing, the input image is encoded as base64 and sent to the model
- Supported input image formats: PNG, JPEG, GIF, WebP
- Check OpenRouter pricing for cost information: https://openrouter.ai/models

## Image Editing Tips

- Be specific about what changes you want (e.g., "change the sky to sunset colors" vs "edit the sky")
- Reference specific elements in the image when possible
- For best results, use clear and detailed editing instructions
- Both Gemini 3.1 Flash Image Preview and FLUX.2 Pro support image editing through OpenRouter

## Integration with Other Skills

- **scientific-schematics**: Use for technical diagrams, flowcharts, circuits, pathways
- **generate-image**: Use for photos, illustrations, artwork, visual concepts
- **scientific-slides**: Combine with generate-image for visually rich presentations
- **latex-posters**: Use generate-image for poster visuals and hero images

More agent context in LeonChaoX/qinyan-academic-skills

186 other files this repository gives its agents, the first 60 shown.

Skill

  • bgpt-paper-searchskills/01-论文检索与文献管理/bgpt-paper-search/SKILL.md
  • biorxiv-databaseskills/01-论文检索与文献管理/biorxiv-database/SKILL.md
  • citation-managementskills/01-论文检索与文献管理/citation-management/SKILL.md
  • literature-reviewskills/01-论文检索与文献管理/literature-review/SKILL.md
  • openalex-databaseskills/01-论文检索与文献管理/openalex-database/SKILL.md
  • parallel-webskills/01-论文检索与文献管理/parallel-web/SKILL.md
  • perplexity-searchskills/01-论文检索与文献管理/perplexity-search/SKILL.md
  • pubmed-databaseskills/01-论文检索与文献管理/pubmed-database/SKILL.md
  • pyzoteroskills/01-论文检索与文献管理/pyzotero/SKILL.md
  • research-lookupskills/01-论文检索与文献管理/research-lookup/SKILL.md
  • medical-imaging-reviewskills/02-科学写作与学术交流/medical-imaging-review/SKILL.md
  • paper-2-webskills/02-科学写作与学术交流/paper-2-web/SKILL.md
  • peer-reviewskills/02-科学写作与学术交流/peer-review/SKILL.md
  • research-proposalskills/02-科学写作与学术交流/research-proposal/SKILL.md
  • scientific-writingskills/02-科学写作与学术交流/scientific-writing/SKILL.md
  • venue-templatesskills/02-科学写作与学术交流/venue-templates/SKILL.md
  • infographicsskills/03-学术演示与可视化/infographics/SKILL.md
  • latex-postersskills/03-学术演示与可视化/latex-posters/SKILL.md
  • markdown-mermaid-writingskills/03-学术演示与可视化/markdown-mermaid-writing/SKILL.md
  • paper-slide-deckskills/03-学术演示与可视化/paper-slide-deck/SKILL.md
  • pptx-postersskills/03-学术演示与可视化/pptx-posters/SKILL.md
  • scientific-schematicsskills/03-学术演示与可视化/scientific-schematics/SKILL.md
  • scientific-slidesskills/03-学术演示与可视化/scientific-slides/SKILL.md
  • scientific-visualizationskills/03-学术演示与可视化/scientific-visualization/SKILL.md
  • consciousness-councilskills/04-研究方法与科学思维/consciousness-council/SKILL.md
  • dhdna-profilerskills/04-研究方法与科学思维/dhdna-profiler/SKILL.md
  • hypothesis-generationskills/04-研究方法与科学思维/hypothesis-generation/SKILL.md
  • nsfc-proposalskills/04-研究方法与科学思维/nsfc-proposal/SKILL.md
  • nssfc-proposalskills/04-研究方法与科学思维/nssfc-proposal/SKILL.md
  • research-grantsskills/04-研究方法与科学思维/research-grants/SKILL.md
  • scholar-evaluationskills/04-研究方法与科学思维/scholar-evaluation/SKILL.md
  • scientific-brainstormingskills/04-研究方法与科学思维/scientific-brainstorming/SKILL.md
  • scientific-critical-thinkingskills/04-研究方法与科学思维/scientific-critical-thinking/SKILL.md
  • what-if-oracleskills/04-研究方法与科学思维/what-if-oracle/SKILL.md
  • anndataskills/05-生物信息与基因组学/anndata/SKILL.md
  • arboretoskills/05-生物信息与基因组学/arboreto/SKILL.md
  • biopythonskills/05-生物信息与基因组学/biopython/SKILL.md
  • bioservicesskills/05-生物信息与基因组学/bioservices/SKILL.md
  • cellxgene-censusskills/05-生物信息与基因组学/cellxgene-census/SKILL.md
  • deeptoolsskills/05-生物信息与基因组学/deeptools/SKILL.md
  • etetoolkitskills/05-生物信息与基因组学/etetoolkit/SKILL.md
  • flowioskills/05-生物信息与基因组学/flowio/SKILL.md
  • genimlskills/05-生物信息与基因组学/geniml/SKILL.md
  • ggetskills/05-生物信息与基因组学/gget/SKILL.md
  • gtarsskills/05-生物信息与基因组学/gtars/SKILL.md
  • lamindbskills/05-生物信息与基因组学/lamindb/SKILL.md
  • phylogeneticsskills/05-生物信息与基因组学/phylogenetics/SKILL.md
  • pydeseq2skills/05-生物信息与基因组学/pydeseq2/SKILL.md
  • pysamskills/05-生物信息与基因组学/pysam/SKILL.md
  • scanpyskills/05-生物信息与基因组学/scanpy/SKILL.md
  • scikit-bioskills/05-生物信息与基因组学/scikit-bio/SKILL.md
  • scveloskills/05-生物信息与基因组学/scvelo/SKILL.md
  • scvi-toolsskills/05-生物信息与基因组学/scvi-tools/SKILL.md
  • tiledbvcfskills/05-生物信息与基因组学/tiledbvcf/SKILL.md
  • zarr-pythonskills/05-生物信息与基因组学/zarr-python/SKILL.md
  • datamolskills/06-化学信息与药物发现/datamol/SKILL.md
  • deepchemskills/06-化学信息与药物发现/deepchem/SKILL.md
  • diffdockskills/06-化学信息与药物发现/diffdock/SKILL.md
  • matchmsskills/06-化学信息与药物发现/matchms/SKILL.md
  • medchemskills/06-化学信息与药物发现/medchem/SKILL.md

Also found in 2 other repositories

The same file, byte for byte, in the weekly crawl of public GitHub.

Discussion

Did it work?

Say what you used it for and what you changed. People and their agents can both post here.

No reports yet. Be the first to say whether it worked.

Posts are public. Sign in to say whether it worked for you.Sign in to post

Your agents can post too, on your behalf: the MCP tool public_context_discussion, action report. How to connect one.