$npx -y skills add Svenja-dev/claude-code-skills --skill gemini-image-genImage generation with Google Gemini API. Models: gemini-2.5-flash-image (fast) or gemini-3-pro-image-preview (quality). For social media graphics, marketing, infographics.
| 1 | # Gemini Image Generation |
| 2 | |
| 3 | Generate images directly from Claude Code CLI using Google's Gemini API. |
| 4 | |
| 5 | ## Setup |
| 6 | |
| 7 | **API Key:** https://aistudio.google.com/apikey |
| 8 | **Environment Variable:** `GOOGLE_AI_API_KEY` |
| 9 | **Install:** `pip install google-genai pillow python-dotenv` |
| 10 | |
| 11 | ## Basic Usage |
| 12 | |
| 13 | ```python |
| 14 | import os |
| 15 | from google import genai |
| 16 | |
| 17 | client = genai.Client(api_key=os.environ.get("GOOGLE_AI_API_KEY")) |
| 18 | |
| 19 | response = client.models.generate_content( |
| 20 | model="gemini-2.5-flash-image", # Fast |
| 21 | # model="gemini-3-pro-image-preview", # Quality |
| 22 | contents=["Your image prompt here"] |
| 23 | ) |
| 24 | |
| 25 | # Extract and save image from response |
| 26 | for part in response.candidates[0].content.parts: |
| 27 | if hasattr(part, 'inline_data') and part.inline_data: |
| 28 | with open("output.png", "wb") as f: |
| 29 | f.write(part.inline_data.data) |
| 30 | ``` |
| 31 | |
| 32 | ## Models |
| 33 | |
| 34 | | Model | Speed | Quality | Use Case | |
| 35 | |-------|-------|---------|----------| |
| 36 | | `gemini-2.5-flash-image` | Fast (~5s) | Good | Drafts, iterations | |
| 37 | | `gemini-3-pro-image-preview` | Slower (~15s) | Excellent | Final assets | |
| 38 | |
| 39 | ## Use Cases |
| 40 | |
| 41 | - Social media graphics |
| 42 | - Marketing materials |
| 43 | - Infographics |
| 44 | - Reddit/Discord banners |
| 45 | - Presentation slides |
| 46 | - Manufacturing dashboards (OEE gauges, SPC charts) |
| 47 | |
| 48 | ## Advanced: Manufacturing Dashboard Example |
| 49 | |
| 50 | ```python |
| 51 | prompt = """ |
| 52 | Create a professional manufacturing OEE dashboard showing: |
| 53 | - Large OEE gauge at 85% (green zone) |
| 54 | - Three smaller KPI cards below: |
| 55 | - Availability: 92% |
| 56 | - Performance: 88% |
| 57 | - Quality: 99.2% |
| 58 | - Dark theme with blue/cyan accents |
| 59 | - Modern, executive-style design |
| 60 | """ |
| 61 | |
| 62 | response = client.models.generate_content( |
| 63 | model="gemini-3-pro-image-preview", |
| 64 | contents=[prompt] |
| 65 | ) |
| 66 | ``` |
| 67 | |
| 68 | ## Image Compression for PPTX |
| 69 | |
| 70 | When embedding in PowerPoint, compress images to avoid silent failures: |
| 71 | |
| 72 | ```python |
| 73 | from PIL import Image |
| 74 | import io |
| 75 | |
| 76 | def compress_image(data: bytes, max_size_kb: int = 200) -> bytes: |
| 77 | img = Image.open(io.BytesIO(data)) |
| 78 | img = img.convert('RGB') |
| 79 | img.thumbnail((1280, 720)) |
| 80 | |
| 81 | buffer = io.BytesIO() |
| 82 | img.save(buffer, format='JPEG', quality=75, optimize=True) |
| 83 | return buffer.getvalue() |
| 84 | ``` |
| 85 | |
| 86 | ## Real-World Usage |
| 87 | |
| 88 | At [fabrikIQ.com](https://www.fabrikiq.com), Gemini Image Generation powers: |
| 89 | - AI-generated OEE dashboard visuals in PPTX exports |
| 90 | - Hero images for executive manufacturing reports |
| 91 | - Marketing materials for LinkedIn posts |