Get the FREE Ultimate OpenClaw Setup Guide →

gemini-image-gen

Scanned
npx machina-cli add skill freitasp1/claude-code-skills/gemini-image-gen --openclaw
Files (1)
SKILL.md
2.5 KB

Gemini Image Generation

Generate images directly from Claude Code CLI using Google's Gemini API.

Setup

API Key: https://aistudio.google.com/apikey Environment Variable: GOOGLE_AI_API_KEY Install: pip install google-genai pillow python-dotenv

Basic Usage

import os
from google import genai

client = genai.Client(api_key=os.environ.get("GOOGLE_AI_API_KEY"))

response = client.models.generate_content(
    model="gemini-2.5-flash-image",  # Fast
    # model="gemini-3-pro-image-preview",  # Quality
    contents=["Your image prompt here"]
)

# Extract and save image from response
for part in response.candidates[0].content.parts:
    if hasattr(part, 'inline_data') and part.inline_data:
        with open("output.png", "wb") as f:
            f.write(part.inline_data.data)

Models

ModelSpeedQualityUse Case
gemini-2.5-flash-imageFast (~5s)GoodDrafts, iterations
gemini-3-pro-image-previewSlower (~15s)ExcellentFinal assets

Use Cases

  • Social media graphics
  • Marketing materials
  • Infographics
  • Reddit/Discord banners
  • Presentation slides
  • Manufacturing dashboards (OEE gauges, SPC charts)

Advanced: Manufacturing Dashboard Example

prompt = """
Create a professional manufacturing OEE dashboard showing:
- Large OEE gauge at 85% (green zone)
- Three smaller KPI cards below:
  - Availability: 92%
  - Performance: 88%
  - Quality: 99.2%
- Dark theme with blue/cyan accents
- Modern, executive-style design
"""

response = client.models.generate_content(
    model="gemini-3-pro-image-preview",
    contents=[prompt]
)

Image Compression for PPTX

When embedding in PowerPoint, compress images to avoid silent failures:

from PIL import Image
import io

def compress_image(data: bytes, max_size_kb: int = 200) -> bytes:
    img = Image.open(io.BytesIO(data))
    img = img.convert('RGB')
    img.thumbnail((1280, 720))

    buffer = io.BytesIO()
    img.save(buffer, format='JPEG', quality=75, optimize=True)
    return buffer.getvalue()

Real-World Usage

At fabrikIQ.com, Gemini Image Generation powers:

  • AI-generated OEE dashboard visuals in PPTX exports
  • Hero images for executive manufacturing reports
  • Marketing materials for LinkedIn posts

Source

git clone https://github.com/freitasp1/claude-code-skills/blob/main/skills/gemini-image-gen/SKILL.mdView on GitHub

Overview

Generates images via Google Gemini API using Claude Code CLI. Choose gemini-2.5-flash-image for speed or gemini-3-pro-image-preview for higher quality, making it ideal for social media graphics, marketing visuals, and infographics.

How This Skill Works

Set up with a Google Gemini API key and the google-genai package. Create a client and call generate_content with the chosen model and prompt contents; then parse the response to extract image data from response.candidates[0].content.parts and save it as a file (e.g., output.png).

When to Use It

  • Creating social media graphics
  • Producing marketing materials
  • Designing infographics
  • Generating banners for Reddit/Discord
  • Building presentation slides

Quick Start

  1. Step 1: Install dependencies and set API key (pip install google-genai pillow python-dotenv; export GOOGLE_AI_API_KEY=your_key)
  2. Step 2: Create a client and call client.models.generate_content with model (gemini-2.5-flash-image for fast) and contents=[prompt]
  3. Step 3: Extract image bytes from response.candidates[0].content.parts and save as output.png

Best Practices

  • Choose gemini-2.5-flash-image for fast drafts and gemini-3-pro-image-preview for final assets
  • Craft clear, specific prompts in the contents list to guide visuals
  • Iterate with quick prompt variations to refine style and layout
  • Compress images before embedding in PPTX to avoid silent failures
  • Maintain design consistency (themes, colors, typography) across assets

Example Use Cases

  • AI-generated OEE dashboard visuals in PPTX exports
  • Hero images for executive manufacturing reports
  • Marketing materials for LinkedIn posts
  • Social media graphics for campaigns
  • Infographics for product or process stories

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers