Skip to content

JuneYaooo/gpt-image2-ppt-skills

gpt-image2-ppt

Verified

Generate visually striking PPT slides via OpenAI's gpt-image-2 -- use any style in styles/<collection>/STYLE_ID.md or mimic a user-supplied .pptx template; outputs high-res slide PNGs and a 16:9 .pptx. Use when the user asks to make a presentation, slides, deck, pitch deck, investor PPT, magazine-style PPT, or 做一份 PPT / 生成幻灯片 / 用 gpt-image 生成 PPT / 按这个模板生成 PPT.

FileKindSize
SKILL.mdskill md56.8 KB
agents/openclaw.yamlconfig1006 B
examples/README.mdmarkdown2.8 KB
examples/book-sharing/recipe.mdmarkdown787 B
examples/book-sharing/slides_plan.mdmarkdown1.8 KB
examples/courseware/recipe.mdmarkdown725 B
examples/courseware/slides_plan.mdmarkdown2.0 KB
examples/editable-pptx-poc/demo1-cover.scene.jsonconfig912 B
examples/editable-pptx/case05-summer-poster/README.mdmarkdown4.1 KB
examples/editable-pptx/case05-summer-poster/clean-plate.pngbinary2.5 MB
examples/editable-pptx/case05-summer-poster/edge-check-black.pngbinary697.7 KB
examples/editable-pptx/case05-summer-poster/edge-check-white.pngbinary695.4 KB
examples/editable-pptx/case05-summer-poster/editable.pptxbinary3.3 MB
examples/editable-pptx/case05-summer-poster/layers/mascot-icecream-group.pngbinary813.1 KB
examples/editable-pptx/case05-summer-poster/original.pngbinary2.4 MB
examples/editable-pptx/case05-summer-poster/quality-report.jsonconfig355 B
examples/editable-pptx/case05-summer-poster/rendered.pngbinary3.7 MB
examples/editable-pptx/case05-summer-poster/slide-01.scene.jsonconfig3.3 KB
examples/investor-pitch/recipe.mdmarkdown803 B
examples/investor-pitch/slides_plan.mdmarkdown2.5 KB
examples/product-launch/recipe.mdmarkdown841 B
examples/product-launch/slides_plan.mdmarkdown1.8 KB
examples/thesis-defense/recipe.mdmarkdown806 B
examples/thesis-defense/slides_plan.mdmarkdown2.4 KB
examples/weekly-report/recipe.mdmarkdown771 B
examples/weekly-report/slides_plan.mdmarkdown1.6 KB
scripts/codex_backend.pyscript9.1 KB
scripts/editable_pptx/__init__.pyscript398 B
scripts/editable_pptx/layers.pyscript2.0 KB
scripts/editable_pptx/masking.pyscript3.8 KB
scripts/editable_pptx/poc.pyscript5.7 KB
scripts/editable_pptx/provider.pyscript2.7 KB
scripts/editable_pptx/renderer.pyscript6.0 KB
scripts/editable_pptx/scene.pyscript4.8 KB
scripts/editable_pptx/workflow.pyscript6.0 KB
scripts/generate_ppt.pyscript162.9 KB
scripts/image_generator.pyscript26.0 KB
scripts/md_to_plan.pyscript5.9 KB
scripts/render_template.pyscript21.7 KB
scripts/runtime_profile.pyscript6.3 KB
scripts/template_analyzer.pyscript42.9 KB

scripts/codex_backend.py

View on GitHub
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Codex CLI backend for image generation.

Instead of calling OpenAI Images API directly (which requires OPENAI_API_KEY),
shell out to `codex exec` and let codex — authenticated via the user's ChatGPT
login or its own configured API key — generate the image and write the PNG.

This backend intentionally starts a separate Codex process. If the caller is
already a Codex agent with native image generation tools, the agent should call
those tools directly and use this repository only for planning / packaging.

Interface is intentionally identical to `image_generator.GptImage2Generator`
so `generate_ppt.py` can swap between them with a single flag.

Tradeoffs vs direct API (documented in SKILL.md):
- Pro: no OPENAI_API_KEY needed in this skill's .env; reuses codex auth.
- Con: slower per image (agent overhead), less reliable parallelism, harder to
  control quality/size precisely — codex interprets the natural-language spec.
"""

from __future__ import annotations

import os
import shlex
import subprocess
from pathlib import Path
from typing import Any, Dict, List, Optional, Union


DEFAULT_CODEX_CMD = "codex exec --full-auto"
DEFAULT_TIMEOUT_SECS = 900  # codex agent loop can be slow per image


class CodexImageBackend:
    """Generate PPT slide PNGs via `codex exec`.

    Env:
      CODEX_CMD    override the codex invocation (default: `codex exec --full-auto`)
                   must be a shell-quoted string; the instruction is appended as
                   a single argv element.
      CODEX_IMAGE_MODEL  model to request codex to use (default: gpt-image-2)
      CODEX_TIMEOUT_SECS per-image timeout (default: 900)
    """

    def __init__(self, aspect_ratio: str = "16:9") -> None:
        self.aspect_ratio = aspect_ratio
        self.codex_cmd = os.getenv("CODEX_CMD", DEFAULT_CODEX_CMD)
        self.model = os.getenv("CODEX_IMAGE_MODEL", "gpt-image-2")
        self.timeout = int(os.getenv("CODEX_TIMEOUT_SECS", str(DEFAULT_TIMEOUT_SECS)))
        self.size = {
            "16:9": "1536x864",
            "9:16": "864x1536",
            "1:1": "1024x1024",
        }.get(aspect_ratio, "1536x864")

        # Sanity check: codex binary reachable?
        exe = shlex.split(self.codex_cmd, posix=os.name != "nt")[0]
        from shutil import which
        if which(exe) is None:
            raise RuntimeError(
                f"codex backend 选中但找不到 `{exe}` 可执行文件。\n"
                f"请先安装 codex CLI(https://github.com/openai/codex)并完成登录,"
                f"或通过 CODEX_CMD 指定完整路径。"
            )

        print(
            f"🎨 初始化 codex backend "
            f"(separate subprocess, cmd={self.codex_cmd!r}, model={self.model}, size={self.size}, "
            f"timeout={self.timeout}s)"
        )

    def _normalize_reference_images(self, reference_image_path: Optional[Union[str, List[str]]]) -> List[str]:
        if not reference_image_path:
            return []
        if isinstance(reference_image_path, (list, tuple)):
            candidates = [str(p) for p in reference_image_path if p]
        else:
            candidates = [str(reference_image_path)]
        return [p for p in candidates if os.path.exists(p)]

    def _build_instruction(
        self,
        prompt: str,
        output_path: str,
        reference_image_path: Optional[Union[str, List[str]]],
    ) -> str:
        abs_out = str(Path(output_path).resolve())
        ref_line = ""
        reference_images = self._normalize_reference_images(reference_image_path)
        if reference_images:
            ref_lines = []
            has_asset_skeleton = False
            has_style_reference = False
            for idx, ref_path in enumerate(reference_images, start=1):
                abs_ref = str(Path(ref_path).resolve())
                if "asset-skeleton" in os.path.basename(ref_path):
                    has_asset_skeleton = True
                    ref_lines.append(f"- 参考图 {idx} 是空间定位图,不是视觉风格参考:{abs_ref}")
                else:
                    has_style_reference = True
                    ref_lines.append(
                        f"- 参考图 {idx} 是视觉风格/模板参考(配色 / 字体 / 装饰元素 / 布局氛围),"
                        f"不要复制其中文字:{abs_ref}"
                    )
            if has_asset_skeleton:
                if has_style_reference:
                    ref_lines.append("- 同时使用模板参考图学习风格,并使用空间定位图避让真实图片后贴区域。")
                ref_lines.append(
                    "- 空间定位图中的细角标表示后续会贴入真实图片的覆盖区;"
                    "不要把标题、正文、数字、图标、人物或主体照片放进这些区域;"
                    "覆盖区底下的背景要自然连续;"
                    "严禁生成白色/浅色矩形、空卡片、图片占位框、边框、阴影、透明洞或任何可见预留块;"
                    "如果页面布局或风格模板提到主体照片、产品照、人物照、场景摄影、photo crop、image crop、图片区或照片区,"
                    "这些角色都由代码后贴真实图片完成,模型不要自行生成、仿造或重绘这些照片内容;"
                    "不要复制、描摹、强化或保留角标。"
                )
            ref_line = "\n".join(ref_lines) + "\n"

        aspect_rule = {
            "16:9": "16:9 横版宽屏(landscape, widescreen, 宽度明显大于高度)",
            "9:16": "9:16 竖版手机屏幕(portrait, vertical)",
            "1:1": "1:1 方图(square)",
        }.get(self.aspect_ratio, "16:9 横版宽屏")

        return (
            f"帮我生成一张 PPT 幻灯片图片,并写到磁盘上。\n\n"
            f"要求:\n"
            f"- 必须使用当前 Codex 会话内置的图片生成能力 / image_generation 工具;"
            f"不要写代码调用 OpenAI API,不要尝试访问网络 API,不要使用需要 DNS 的 HTTP 请求。\n"
            f"- 目标图片模型:{self.model}\n"
            f"- 尺寸:{self.size}({aspect_rule})\n"
            f"- 质量:high\n"
            f"- 输出路径(绝对路径):{abs_out}\n"
            f"{ref_line}"
            f"- 保存后确认文件存在且体积 > 10KB;若失败请报错退出非零。\n"
            f"- 不要向我解释或改写 prompt,直接出图。\n\n"
            f"图片 prompt:\n"
            f"-----BEGIN PROMPT-----\n"
            f"{prompt}\n"
            f"-----END PROMPT-----\n"
        )

    def generate_scene_image(
        self,
        scene_data: Dict[str, Any],
        output_path: str,
        size: str = "auto",
        reference_image_path: Optional[Union[str, List[str]]] = None,
    ) -> str:
        scene_index = scene_data.get("index", 0)
        prompt = scene_data.get("image_prompt", "")
        if not prompt:
            raise ValueError(f"场景 {scene_index} 缺少 image_prompt")

        out_dir = os.path.dirname(output_path)
        if out_dir:
            os.makedirs(out_dir, exist_ok=True)

        instruction = self._build_instruction(prompt, output_path, reference_image_path)
        argv = shlex.split(self.codex_cmd) + [instruction]

        print(f"🔗 [scene {scene_index}] dispatching to codex ({len(instruction)} chars)")
        try:
            result = subprocess.run(
                argv,
                capture_output=True,
                text=True,
                timeout=self.timeout,
                check=False,
            )
        except subprocess.TimeoutExpired as e:
            raise RuntimeError(f"codex exec 超时({self.timeout}s): {e}") from e

        # Codex writes progress to stderr; log tail for debugging without spamming.
        stderr_tail = (result.stderr or "").strip().splitlines()[-5:]
        if stderr_tail:
            for line in stderr_tail:
                print(f"  ↳ {line[:200]}")

        if result.returncode != 0:
            raise RuntimeError(
                f"codex exec 非零退出 (code={result.returncode}): "
                f"{(result.stderr or result.stdout or '')[-500:]}"
            )

        if not os.path.exists(output_path):
            raise RuntimeError(
                f"codex 声称成功但文件不存在: {output_path}\n"
                f"stdout tail: {(result.stdout or '')[-300:]}"
            )

        size_bytes = os.path.getsize(output_path)
        if size_bytes < 10 * 1024:
            raise RuntimeError(
                f"codex 产出的文件过小 ({size_bytes} bytes),可能是错误页/空文件:{output_path}"
            )

        print(f"[OK] 已保存: {output_path}  ({size_bytes // 1024} KB)")
        return output_path


if __name__ == "__main__":
    import sys
    gen = CodexImageBackend(aspect_ratio="16:9")
    gen.generate_scene_image(
        {"index": 0, "image_prompt": "A clean blue gradient background with the bold white text 'codex backend test'"},
        "test_codex_output.png",
    )
    print(f"自检完成: {Path('test_codex_output.png').resolve()}")
    sys.exit(0)
canvas-designanthropics/skillsCreate beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
docxanthropics/skillsUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
pdfanthropics/skillsUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
pptxanthropics/skillsUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill.Stars: 198kUpdated Claude CodeCodexVerifiedInstall