Home
cd ../playbooks
Creative & DesignBeginner

Scientific Generate Image

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 flowchart...

5 minutes
By K-Dense AISource
#scientific#claude-code#generate-image#bioinformatics#machine-learning#visualization#database#protein

You need a custom illustration, concept visualization, or creative asset but don't have a designer on call or the budget for stock photography. AI image generation with FLUX and other models lets you go from text description to high-quality visuals — iterating on style, composition, and content until you get exactly what you need.

Who it's for: content creators needing custom visuals for articles and social media, researchers generating scientific illustrations and concept diagrams, marketers creating visual assets without waiting for design team turnaround, educators producing custom educational imagery, product teams creating mockups and concept art for presentations

Example

"Generate a hero image for our blog post about protein folding" → AI-generated image: FLUX-generated visualization matching your description, multiple style variations to choose from, resolution suitable for web or print, iterative refinement based on feedback, and final output in publication-ready format

CLAUDE.md Template

New here? 3-minute setup guide → | Already set up? Copy the template below.

Or install from your terminal:
npx ccplaybooks add scientific-generate-image
# 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

Get new playbooks like this one

One email a week with new Claude Code workflows. Free, like everything here.

No spam. Unsubscribe anytime.

README.md

What This Does

A scientific skill for generate image workflows with Claude Code.


Quick Start

Step 1: Create a Project Folder

mkdir -p ~/Projects/generate-image

Step 2: Download the Template

Click Download above, then:

mv ~/Downloads/CLAUDE.md ~/Projects/generate-image/

Step 3: Start Claude Code

cd ~/Projects/generate-image
claude

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

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

python scripts/generate_image.py "Your prompt here"

Specify model

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

Custom output path

python scripts/generate_image.py "Abstract art" --output artwork.png

Edit an existing image

python scripts/generate_image.py "Make the background blue" --input photo.jpg

Edit with a specific model

python scripts/generate_image.py "Add sunglasses to the person" --input portrait.png --model "black-forest-labs/flux.2-pro"

Edit with custom output

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:

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

# 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

# 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

# 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 Workflows

  • 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

Tips

  • Read the docs: Check the official generate-image documentation for latest API changes
  • Start simple: Begin with basic examples before tackling complex workflows
  • Save your work: Keep intermediate results in case of long-running analyses

$Related Playbooks

Creative & Design

Scientific Latex Posters

'Create professional research posters in LaTeX using beamerposter, tikzposter, or baposter. Support for conference presentations, academic posters, and scientific communication. Includes layout design, color schemes, multi-column formats, figure i...

10 minutes
Intermediate
Creative & Design

Theme Factory

Apply professional themes to presentations, documents, and landing pages with 10 pre-set themes plus custom theme generation.

5 minutes
Beginner
Creative & Design

Accessibility Auditor

WCAG 2.1 AA accessibility audit for designs, prototypes, and web pages

10 minutes
Intermediate
Creative & Design

AI Design Director System

Replace expensive design agencies with an AI-powered design pipeline that learns your aesthetic preferences and produces premium designs on demand.

2 hours
Advanced
Creative & Design

Canvas Design

Create museum-quality visual art and design philosophy documents in PNG and PDF formats using Anthropic's canvas-design principles.

10 minutes
Advanced
Creative & Design

Apple Fluid Interface Design for the Web

Apple's approach to gesture-driven UI and physical motion — from WWDC's Designing Fluid Interfaces — translated to CSS, Pointer Events, and spring animation libraries: interruptibility, velocity handoff, momentum projection, rubber-banding, and translucent materials.

10 minutes
Advanced
Creative & Design

AI Presentation Generator

Generate complete presentations with AI - from outline to polished slides

10 minutes
Intermediate
Creative & Design

Design Critique Reviewer

Structured design feedback across usability, visual hierarchy, and consistency

10 minutes
Intermediate
Creative & Design

Design Handoff Generator

Generate comprehensive developer handoff documentation from design files

10 minutes
Intermediate
Creative & Design

Design System Manager

Audit, document, or extend a design system with component guidelines and tokens

10 minutes
Advanced
Creative & Design

Diagram & Flowchart Creator

Create professional diagrams using Mermaid, PlantUML, and other text-based diagram tools. Generate flowcharts, sequence diagrams, architecture diagrams, and more.

10 minutes
Advanced
Creative & Design

Excalidraw Diagram Generator

Generate Excalidraw diagrams directly from text in three formats — Obsidian-ready .md, standalone .excalidraw for excalidraw.com, and an animated .excalidraw with per-element playback order — with the exact JSON element schema (including the undocumented fields that break excalidraw.com if included), a font-size floor, and a full color palette with contrast rules.

5 minutes
Intermediate

Browse all Creative & Design playbooks →