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/editable_pptx/renderer.py

View on GitHub
"""Render an EditableScene as native PowerPoint objects."""

from __future__ import annotations

from pathlib import Path

from pptx import Presentation
from pptx.dml.color import RGBColor
from pptx.enum.shapes import MSO_AUTO_SHAPE_TYPE, MSO_CONNECTOR
from pptx.enum.text import MSO_ANCHOR, PP_ALIGN
from pptx.oxml.xmlchemy import OxmlElement
from pptx.util import Inches, Pt

from .scene import EditableScene, SceneElement


ALIGNMENTS = {
    "left": PP_ALIGN.LEFT,
    "center": PP_ALIGN.CENTER,
    "right": PP_ALIGN.RIGHT,
}
VERTICAL_ALIGNMENTS = {
    "top": MSO_ANCHOR.TOP,
    "middle": MSO_ANCHOR.MIDDLE,
    "bottom": MSO_ANCHOR.BOTTOM,
}
SHAPE_TYPES = {
    "rectangle": MSO_AUTO_SHAPE_TYPE.RECTANGLE,
    "rounded_rectangle": MSO_AUTO_SHAPE_TYPE.ROUNDED_RECTANGLE,
    "ellipse": MSO_AUTO_SHAPE_TYPE.OVAL,
    "star_5": MSO_AUTO_SHAPE_TYPE.STAR_5_POINT,
}


def _hex_color(value: str) -> RGBColor:
    normalized = value.strip().lstrip("#")
    if len(normalized) != 6:
        raise ValueError(f"无效颜色: {value}")
    return RGBColor.from_string(normalized.upper())


def _slide_bbox(prs: Presentation, scene: EditableScene, element: SceneElement) -> tuple[int, int, int, int]:
    x, y, width, height = element.bbox_px
    return (
        int(x / scene.canvas_width * prs.slide_width),
        int(y / scene.canvas_height * prs.slide_height),
        int(width / scene.canvas_width * prs.slide_width),
        int(height / scene.canvas_height * prs.slide_height),
    )


def _add_text(prs: Presentation, slide, scene: EditableScene, element: SceneElement) -> None:
    left, top, width, height = _slide_bbox(prs, scene, element)
    shape = slide.shapes.add_textbox(left, top, width, height)
    shape.name = element.id
    frame = shape.text_frame
    frame.clear()
    frame.margin_left = 0
    frame.margin_right = 0
    frame.margin_top = 0
    frame.margin_bottom = 0
    frame.word_wrap = True
    frame.vertical_anchor = VERTICAL_ALIGNMENTS.get(
        str(element.style.get("vertical_align", "middle")), MSO_ANCHOR.MIDDLE
    )

    paragraph = frame.paragraphs[0]
    paragraph.alignment = ALIGNMENTS.get(str(element.style.get("align", "left")), PP_ALIGN.LEFT)
    run = paragraph.add_run()
    run.text = element.content
    font = run.font
    font.name = str(element.style.get("font_face", "Noto Sans CJK SC"))
    font.size = Pt(float(element.style.get("font_size_pt", 24)))
    font.bold = int(element.style.get("font_weight", 400)) >= 600
    font.color.rgb = _hex_color(str(element.style.get("color", "#000000")))


def _add_shape(prs: Presentation, slide, scene: EditableScene, element: SceneElement) -> None:
    shape_name = str(element.style.get("shape"))
    if shape_name == "line":
        _add_connector(prs, slide, scene, element)
        return
    left, top, width, height = _slide_bbox(prs, scene, element)
    shape = slide.shapes.add_shape(SHAPE_TYPES[shape_name], left, top, width, height)
    shape.name = element.id
    fill_color = element.style.get("fill")
    if fill_color:
        shape.fill.solid()
        shape.fill.fore_color.rgb = _hex_color(str(fill_color))
        shape.fill.transparency = float(element.style.get("fill_transparency", 0))
    else:
        shape.fill.background()
    line_color = element.style.get("line")
    if line_color:
        shape.line.color.rgb = _hex_color(str(line_color))
        shape.line.transparency = float(element.style.get("line_transparency", 0))
        shape.line.width = Pt(float(element.style.get("line_width_pt", 1)))
    else:
        shape.line.fill.background()
    shape.rotation = float(element.style.get("rotation", 0))


def _add_connector(prs: Presentation, slide, scene: EditableScene, element: SceneElement) -> None:
    left, top, width, height = _slide_bbox(prs, scene, element)
    connector = slide.shapes.add_connector(
        MSO_CONNECTOR.STRAIGHT,
        left,
        top,
        left + width,
        top + height,
    )
    connector.name = element.id
    connector.line.color.rgb = _hex_color(str(element.style.get("line", "#000000")))
    connector.line.width = Pt(float(element.style.get("line_width_pt", 1)))
    connector.line.transparency = float(element.style.get("line_transparency", 0))
    if element.style.get("end_arrow"):
        line_properties = connector.line._get_or_add_ln()
        tail_end = OxmlElement("a:tailEnd")
        tail_end.set("type", "triangle")
        line_properties.append(tail_end)


def _render_element(prs: Presentation, slide, scene: EditableScene, element: SceneElement) -> None:
    if element.type == "image_layer":
        left, top, width, height = _slide_bbox(prs, scene, element)
        picture = slide.shapes.add_picture(str(element.asset), left, top, width=width, height=height)
        picture.name = element.id
    elif element.type == "native_text":
        _add_text(prs, slide, scene, element)
    elif element.type == "native_shape":
        _add_shape(prs, slide, scene, element)
    elif element.type == "connector":
        _add_connector(prs, slide, scene, element)


def add_editable_slide(prs: Presentation, scene: EditableScene):
    slide = prs.slides.add_slide(prs.slide_layouts[6])
    clean_plate = slide.shapes.add_picture(
        str(scene.clean_plate),
        0,
        0,
        width=prs.slide_width,
        height=prs.slide_height,
    )
    clean_plate.name = "clean_plate"
    for element in sorted(scene.elements, key=lambda item: item.z_index):
        _render_element(prs, slide, scene, element)
    return slide


def render_editable_deck(scenes, output_path: Path | str) -> Path:
    ordered = sorted(scenes, key=lambda scene: scene.slide_number)
    if not ordered:
        raise ValueError("至少需要一个 editable scene")
    prs = Presentation()
    prs.slide_width = Inches(13.333)
    prs.slide_height = Inches(7.5)
    for scene in ordered:
        add_editable_slide(prs, scene)
    path = Path(output_path)
    path.parent.mkdir(parents=True, exist_ok=True)
    prs.save(path)
    return path


def render_editable_pptx(scene: EditableScene, output_path: Path | str) -> Path:
    return render_editable_deck([scene], output_path)
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