Back to .md Directory

Gemini PPTX Image Skill

Generates an image via the Gemini API and inserts it into a specified PowerPoint slide, replacing a content placeholder if one exists.

May 2, 2026
0 downloads
3 views
ai prompt gemini
View source

What this file does

Generates an image via the Gemini API and inserts it into a specified PowerPoint slide, replacing a content placeholder if one exists.

When to use it

  • Adding AI-generated visuals to a slide deck
  • Automating image creation for presentation content
  • Replacing placeholder images on slides with generated ones
  • Building a script that combines Gemini image generation with PPTX editing

Assumes this stack

Gemini APIPythonpython-pptxBashcurl

name: gemini-pptx description: Generate images with Gemini and insert them into PowerPoint files. Use this skill whenever the user asks to add an AI-generated image to a PowerPoint slide. tools:

  • Bash
  • Read
  • Write
  • Glob

Gemini PPTX Image Skill

Generate an image using the Gemini API and insert it into a PowerPoint slide.

Configuration

GEMINI_API_KEY=YOUR_GEMINI_API_KEY_HERE GEMINI_MODEL=gemini-2.5-flash-image

Step 1 — Generate image

Decide on an image prompt based on the slide content. Do NOT ask the user for a prompt unless they explicitly provided one.

curl -s -X POST \
  "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image:generateContent?key=YOUR_GEMINI_API_KEY_HERE" \
  -H "Content-Type: application/json" \
  -d '{"contents":[{"parts":[{"text":"PROMPT_HERE"}]}],"generationConfig":{"responseModalities":["IMAGE","TEXT"]}}' \
  | python3 -c "
import json, sys, base64
d = json.load(sys.stdin)
if 'error' in d:
    print('ERROR:', d['error']['message'])
    sys.exit(1)
for p in d['candidates'][0]['content']['parts']:
    if 'inlineData' in p:
        img = base64.b64decode(p['inlineData']['data'])
        with open('/tmp/gemini_slide_image.png', 'wb') as f:
            f.write(img)
        print('SAVED ' + str(len(img)) + ' bytes')
        break
"

Step 2 — Install python-pptx if needed

python3 -c "import pptx" 2>/dev/null || pip install python-pptx -q

Step 3 — Insert image into slide

python3 - << 'EOF'
from pptx import Presentation

pptx_path = "PPTX_PATH_HERE"
slide_number = SLIDE_NUMBER_HERE  # 1-based
image_path = "/tmp/gemini_slide_image.png"

prs = Presentation(pptx_path)
slide = prs.slides[slide_number - 1]

target = None
for shape in slide.placeholders:
    if shape.placeholder_format.type in (18, 15, 14):
        target = shape
        break

if target:
    left, top, width, height = target.left, target.top, target.width, target.height
    target._element.getparent().remove(target._element)
else:
    left = int(prs.slide_width * 0.5)
    top = int(prs.slide_height * 0.1)
    width = int(prs.slide_width * 0.45)
    height = int(prs.slide_height * 0.8)

slide.shapes.add_picture(image_path, left, top, width, height)
prs.save(pptx_path)
print("Done")
EOF

Rules

  • Never use a proxy server. Call Gemini API directly using the key above.
  • Never ask the user for an image prompt. Choose based on slide content.
  • If curl returns an error, show it to the user.

What's inside

3 steps (generate image, install dependency, insert into slide) plus configuration and rules, with 3 code blocks.

Change this for your project

  • Replace YOUR_GEMINI_API_KEY_HERE with your actual Gemini API key
  • Replace PPTX_PATH_HERE with the path to your target PowerPoint file
  • Replace SLIDE_NUMBER_HERE with the 1-based slide index
  • Replace PROMPT_HERE with the image prompt text

Where it goes

Save as SKILL.md inside a skill folder. Loaded when the agent selects that skill.

Worth borrowing

  • Detecting and replacing a content placeholder by type rather than hardcoding coordinates
  • Using a fallback position when no placeholder exists, based on slide dimensions

Related Documents