AI turns documents or topics into real, native PowerPoint decks—with native shapes, transitions and animations, data-backed charts and tables on demand, audio narration from speaker notes, and support for your own .pptx templates. · by Hugo He
feat(pptx-roundtrip): preserve picture opacity
hugohe35a2c67d68fc0
diff --git a/skills/ppt-master/scripts/pptx_to_svg/pic_to_svg.py b/skills/ppt-master/scripts/pptx_to_svg/pic_to_svg.pyindex 21e3e2ab..b3ba9038 100644--- a/skills/ppt-master/scripts/pptx_to_svg/pic_to_svg.py+++ b/skills/ppt-master/scripts/pptx_to_svg/pic_to_svg.py@@ -104,6 +104,7 @@ def convert_blip_fill(filename, img_bytes = _normalize_office_media(filename, img_bytes)filename, img_bytes = _apply_blip_image_effects(filename, img_bytes, blip)href = _build_href(filename, img_bytes, media_subdir, embed_inline)+ opacity_attr = _blip_opacity_attr(blip)# srcRect: l/t/r/b in 1/100000ths (so 50000 = 50%).src_rect = blip_fill_elem.find("a:srcRect", NS)@@ -120,7 +121,7 @@ def convert_blip_fill(svg = (f'<image href="{href}" x="{fmt_num(xfrm.x)}" y="{fmt_num(xfrm.y)}" 'f'width="{fmt_num(xfrm.w)}" height="{fmt_num(xfrm.h)}" '- f'preserveAspectRatio="none"/>'+ f'preserveAspectRatio="none"{opacity_attr}/>')else:# Crop expressed as a unit-rectangle viewBox on a nested <svg>.@@ -132,7 +133,7 @@ def convert_blip_fill(f'{fmt_num(vb_w, 5)} {fmt_num(vb_h, 5)}" 'f'preserveAspectRatio="none">'f'<image href="{href}" x="0" y="0" width="1" height="1" '- f'preserveAspectRatio="none"/>'+ f'preserveAspectRatio="none"{opacity_attr}/>'f"</svg>")@@ -169,6 +170,20 @@ def convert_picture(# Helpers# ---------------------------------------------------------------------------++def _blip_opacity_attr(blip: ET.Element) -> str:+ """Translate DrawingML fixed image alpha to an SVG opacity attribute."""+ alpha = blip.find("a:alphaModFix", NS)+ if alpha is None:+ return ""+ try:+ opacity = max(0.0, min(1.0, float(alpha.attrib.get("amt", "100000")) / 100000.0))+ except ValueError:+ return ""+ if opacity >= 1.0:+ return ""+ return f' opacity="{fmt_num(opacity, 5)}"'+_OFFICE_VECTOR_EXTS = {".emf", ".wmf"}diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.pyindex b19d0834..0ad4e408 100644--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py@@ -30,7 +30,7 @@ from .utils import (from .styles import (build_solid_fill, build_gradient_fill,build_fill_xml, build_stroke_xml, build_effect_xml, classify_filter_effect,- get_fill_opacity, get_stroke_opacity,+ get_element_opacity, get_fill_opacity, get_stroke_opacity,)from .paths import (PathCommand, parse_svg_path, svg_path_to_absolute,@@ -2369,6 +2369,18 @@ def _resolve_image_meet_fit(return (dx, dy, fit_w, fit_h)+def _build_image_blip_xml(r_id: str, opacity: float | None) -> str:+ """Build an image blip with native DrawingML transparency when requested."""+ if opacity is None:+ return f'<a:blip r:embed="{r_id}"/>'+ alpha = int(round(opacity * 100000))+ return (+ f'<a:blip r:embed="{r_id}">'+ f'<a:alphaModFix amt="{alpha}"/>'+ '</a:blip>'+ )++def convert_image(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:"""Convert SVG <image> to DrawingML picture element.@@ -2439,6 +2451,7 @@ def convert_image(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:# Image optimization only downscales the full source image; it never crops# pixels out of the embedded media.src_rect_xml = _resolve_image_src_rect(elem, img_data, w, h)+ blip_xml = _build_image_blip_xml(r_id, get_element_opacity(elem, ctx))# Resolve preserveAspectRatio="<align> meet" by shrinking the picture# frame to match the image's aspect ratio. Skipped when a real clip-path@@ -2495,7 +2508,7 @@ def convert_image(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:<p:nvPr/></p:nvPicPr><p:blipFill>-<a:blip r:embed="{r_id}"/>+{blip_xml}{src_rect_xml}<a:stretch><a:fillRect/></a:stretch></p:blipFill><p:spPr>@@ -2668,6 +2681,10 @@ def convert_nested_svg(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | Ntransform,)clip_geom = _resolve_clip_geometry(elem, ctx, svg_x, svg_y, svg_w, svg_h)+ blip_xml = _build_image_blip_xml(+ r_id,+ get_element_opacity(image_elem, ctx),+ )return ShapeResult(xml=f'''<p:pic><p:nvPicPr>@@ -2676,7 +2693,7 @@ def convert_nested_svg(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | N<p:nvPr/></p:nvPicPr><p:blipFill>-<a:blip r:embed="{r_id}"/>+{blip_xml}{src_rect_xml}<a:stretch><a:fillRect/></a:stretch></p:blipFill><p:spPr>diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/styles.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/styles.pyindex 554e52cb..bf2ab7a5 100644--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/styles.py+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/styles.py@@ -621,13 +621,16 @@ def build_effect_xml(filter_elem: ET.Element) -> str:return ''-def get_element_opacity(elem: ET.Element) -> float | None:- """Get opacity value from element. Returns None if 1.0 or not set."""- op = elem.get('opacity')+def get_element_opacity(+ elem: ET.Element,+ ctx: ConvertContext | None = None,+) -> float | None:+ """Get the effective element opacity, clamped to the SVG ``0..1`` range."""+ op = _get_attr(elem, 'opacity', ctx) if ctx else elem.get('opacity')if op is None:return Nonetry:- val = float(op)+ val = max(0.0, min(1.0, float(op)))return val if val < 1.0 else Noneexcept ValueError:return None