Skip to content

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(scripts): -o directory for one input, backend aspect-ratio check, image_treat --fit

hugohe34f8678eac1c8
diff --git a/skills/ppt-master/scripts/image_gen.py b/skills/ppt-master/scripts/image_gen.py
index 854a478c..12b6eeb5 100644
--- a/skills/ppt-master/scripts/image_gen.py
+++ b/skills/ppt-master/scripts/image_gen.py
@@ -371,6 +371,21 @@ def _print_backend_list() -> None:
_print_backend_resolution()
+def _check_backend_aspect_ratio(backend_module, aspect_ratio: str) -> None:
+ """Fail before the request when the resolved backend rejects this ratio.
+
+ ``ALL_ASPECT_RATIOS`` is the union across backends; each backend module
+ may narrow it with ``VALID_ASPECT_RATIOS``.
+ """
+ valid = getattr(backend_module, "VALID_ASPECT_RATIOS", None)
+ if valid and aspect_ratio not in valid:
+ name = getattr(backend_module, "__name__", "backend").rsplit(".", 1)[-1]
+ raise ValueError(
+ f"aspect_ratio '{aspect_ratio}' is not supported by {name}. "
+ f"Valid for this backend: {list(valid)}"
+ )
+
+
def _resolve_backend() -> tuple[object, str]:
"""
Determine which backend to use from explicit configuration.
@@ -950,6 +965,7 @@ def _run_manifest(manifest: dict, manifest_path: str, backend_module, *,
def _one(idx: int):
item = items[idx]
try:
+ _check_backend_aspect_ratio(backend_module, item["aspect_ratio"])
saved_path = backend_module.generate(
prompt=item["prompt"],
aspect_ratio=item["aspect_ratio"],
diff --git a/skills/ppt-master/scripts/image_treat.py b/skills/ppt-master/scripts/image_treat.py
index e0ba92f6..a1f2b612 100644
--- a/skills/ppt-master/scripts/image_treat.py
+++ b/skills/ppt-master/scripts/image_treat.py
@@ -17,7 +17,7 @@ Dependencies:
Pillow; project image-search dependencies when copying web provenance
Treatments run in this fixed order: brightness, contrast, tone treatment
-(desaturate / grayscale / duotone), then Gaussian blur.
+(desaturate / grayscale / duotone), Gaussian blur, then --fit downscaling.
"""
from __future__ import annotations
@@ -98,6 +98,19 @@ def _unit_float(value: str) -> float:
return number
+_FIT_RE = re.compile(r"^(\d+)x(\d+)$")
+
+
+def _fit_box(value: str) -> tuple[int, int]:
+ match = _FIT_RE.fullmatch(value.strip().lower())
+ if match is None:
+ raise argparse.ArgumentTypeError("fit box must be WIDTHxHEIGHT in pixels, e.g. 920x228")
+ width, height = int(match.group(1)), int(match.group(2))
+ if width <= 0 or height <= 0:
+ raise argparse.ArgumentTypeError("fit box dimensions must be positive")
+ return width, height
+
+
def _hex_color(value: str) -> str:
match = _HEX_COLOR_RE.fullmatch(value)
if match is None:
@@ -156,6 +169,17 @@ def build_parser() -> argparse.ArgumentParser:
type=_nonnegative_float,
help="Gaussian blur radius greater than or equal to 0; 0 is unchanged.",
)
+ parser.add_argument(
+ "--fit",
+ type=_fit_box,
+ default=None,
+ metavar="WxH",
+ help=(
+ "Downscale so the image fits inside WIDTHxHEIGHT pixels, preserving "
+ "aspect ratio and alpha; never upscales. Use it to bring an "
+ "oversized generated image down to its planned on-slide size."
+ ),
+ )
return parser
@@ -245,6 +269,8 @@ def _treatment_plan(args: argparse.Namespace) -> list[dict]:
)
if args.blur is not None and args.blur > 0:
plan.append({"operation": "blur", "radius": args.blur})
+ if args.fit is not None:
+ plan.append({"operation": "fit", "width": args.fit[0], "height": args.fit[1]})
if not plan:
raise ValueError(
"select at least one effective treatment; identity values such as "
@@ -344,6 +370,19 @@ def _apply_treatments(
result = rgb.convert("RGBA") if alpha is not None else rgb
if alpha is not None:
result.putalpha(alpha)
+ if args.fit is not None:
+ fit_w, fit_h = args.fit
+ scale = min(fit_w / width, fit_h / height, 1.0)
+ if scale < 1.0:
+ new_size = (
+ max(1, round(width * scale)),
+ max(1, round(height * scale)),
+ )
+ resized = result.resize(new_size, Image.Resampling.LANCZOS)
+ if result is not rgb:
+ result.close()
+ result = resized
+ width, height = new_size
save_options = {"format": "PNG"}
if isinstance(icc_profile, bytes) and icc_profile:
save_options["icc_profile"] = icc_profile
diff --git a/skills/ppt-master/scripts/source_to_md.py b/skills/ppt-master/scripts/source_to_md.py
index 68bb3d93..c6e945ce 100644
--- a/skills/ppt-master/scripts/source_to_md.py
+++ b/skills/ppt-master/scripts/source_to_md.py
@@ -22,6 +22,7 @@ from __future__ import annotations
import argparse
import json
+import os
import subprocess
import sys
import tempfile
@@ -67,6 +68,15 @@ def _is_supported_directory_item(path: Path) -> bool:
}
+def _output_is_directory(output_arg: str | None) -> bool:
+ """True when -o names an existing directory or ends with a path separator."""
+ if not output_arg:
+ return False
+ if output_arg.endswith(("/", os.sep)):
+ return True
+ return Path(output_arg).is_dir()
+
+
def _dispatch_output_arg(
input_arg: str,
conversion_type: str,
@@ -74,6 +84,11 @@ def _dispatch_output_arg(
batch_mode: bool,
used_outputs: set[Path],
) -> str | None:
+ if output_arg and _output_is_directory(output_arg):
+ # A directory is a directory even for one input: the file keeps its
+ # default `<stem>.md` name inside it instead of becoming an
+ # extension-less file named after the directory.
+ batch_mode = True
if output_arg and batch_mode and conversion_type == "web":
return None
if output_arg and batch_mode:
@@ -351,7 +366,7 @@ converter, so existing converter behavior remains the source of truth.
parser.add_argument(
"-o",
"--output",
- help="Output Markdown file for one input, or output directory for multiple inputs/directories",
+ help="Output Markdown file for one input, or output directory (an existing directory or a path ending in /) for one or more inputs",
)
parser.add_argument(
"--images",
@@ -411,7 +426,7 @@ def dispatch_many(
success_count = 0
failed: list[str] = []
skipped: list[str] = list(initial_failures or [])
- batch_mode = batch_mode or len(inputs) > 1
+ batch_mode = batch_mode or len(inputs) > 1 or _output_is_directory(args.output)
if args.output and batch_mode:
output_dir = Path(args.output)
if output_dir.exists() and not output_dir.is_dir():