siril9/presentation-skill / plugins/presentation-skill/skills/presentation-skill
presentation-skill
FlaggedBuild, edit, redesign, render, and verify content-led, structurally diverse, clean, editable, reproducible PowerPoint `.pptx` decks. Use for scientific, lab, clinical, consulting, board, investor, editorial, policy, and operational presentations where alignment, readability, contrast, and balanced density matter.
scripts/trim_image_whitespace.py
View on GitHub#!/usr/bin/env python3
"""Trim near-blank borders from slide figures.
Use this from workspace figure scripts before inserting generated plots into
`scientific-figure` or `image-sidebar` slides. It removes exterior whitespace
from PNG/JPG assets while leaving the original deck source workflow intact.
"""
from __future__ import annotations
import argparse
import json
import shutil
import sys
from pathlib import Path
from typing import Any
try:
from PIL import Image, ImageChops
except Exception as exc: # pragma: no cover - dependency error path
print(f"Error: Pillow is required for image trimming: {exc}", file=sys.stderr)
raise SystemExit(1)
def _corner_background(img: Image.Image) -> tuple[int, int, int, int]:
rgba = img.convert("RGBA")
w, h = rgba.size
corners = [
rgba.getpixel((0, 0)),
rgba.getpixel((max(0, w - 1), 0)),
rgba.getpixel((0, max(0, h - 1))),
rgba.getpixel((max(0, w - 1), max(0, h - 1))),
]
return tuple(sorted(values)[len(values) // 2] for values in zip(*corners)) # type: ignore[return-value]
def _content_bbox(img: Image.Image, *, tolerance: int) -> tuple[int, int, int, int] | None:
rgba = img.convert("RGBA")
bg = Image.new("RGBA", rgba.size, _corner_background(rgba))
diff = ImageChops.difference(rgba, bg)
mask = Image.new("L", rgba.size, 0)
for channel in diff.split():
thresholded = channel.point(lambda value: 255 if value > tolerance else 0)
mask = ImageChops.lighter(mask, thresholded)
return mask.getbbox()
def _pad_bbox(
bbox: tuple[int, int, int, int],
*,
width: int,
height: int,
padding: int,
) -> tuple[int, int, int, int]:
left, top, right, bottom = bbox
return (
max(0, left - padding),
max(0, top - padding),
min(width, right + padding),
min(height, bottom + padding),
)
def trim_image(
input_path: Path,
output_path: Path,
*,
tolerance: int,
padding: int,
overwrite: bool,
) -> dict[str, Any]:
if not input_path.exists():
raise FileNotFoundError(input_path)
if output_path.exists() and not overwrite and output_path.resolve() != input_path.resolve():
raise FileExistsError(f"Output exists: {output_path}")
with Image.open(input_path) as raw:
img = raw.convert("RGBA")
bbox = _content_bbox(img, tolerance=tolerance)
if not bbox:
if input_path.resolve() != output_path.resolve():
output_path.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(input_path, output_path)
return {
"input": str(input_path),
"output": str(output_path),
"status": "unchanged",
"original_size": list(img.size),
"trimmed_size": list(img.size),
}
padded = _pad_bbox(bbox, width=img.width, height=img.height, padding=padding)
cropped = img.crop(padded)
output_path.parent.mkdir(parents=True, exist_ok=True)
save_kwargs: dict[str, Any] = {}
suffix = output_path.suffix.lower()
if suffix in {".jpg", ".jpeg"}:
cropped = cropped.convert("RGB")
save_kwargs["quality"] = 95
cropped.save(output_path, **save_kwargs)
return {
"input": str(input_path),
"output": str(output_path),
"status": "trimmed" if cropped.size != img.size else "unchanged",
"original_size": list(img.size),
"trimmed_size": list(cropped.size),
"bbox": list(padded),
}
def _output_path(input_path: Path, args: argparse.Namespace) -> Path:
if args.in_place:
return input_path
name = f"{input_path.stem}{args.suffix}{input_path.suffix}"
if args.outdir:
return Path(args.outdir).expanduser().resolve() / name
return input_path.with_name(name)
def main() -> int:
parser = argparse.ArgumentParser(description="Trim near-blank borders from generated slide figures.")
parser.add_argument("images", nargs="+", help="Input image paths")
parser.add_argument("--outdir", help="Optional output directory")
parser.add_argument("--suffix", default="_tight", help="Suffix for output files when not using --in-place")
parser.add_argument("--in-place", action="store_true", help="Overwrite each input image")
parser.add_argument("--overwrite", action="store_true", help="Overwrite existing output files")
parser.add_argument("--tolerance", type=int, default=12, help="Pixel difference threshold from inferred background")
parser.add_argument("--padding", type=int, default=10, help="Pixels of padding to retain around detected content")
args = parser.parse_args()
if args.in_place:
args.overwrite = True
if not args.in_place and args.suffix == "":
parser.error("--suffix cannot be empty unless --in-place is used")
reports = []
for raw in args.images:
input_path = Path(raw).expanduser().resolve()
output_path = _output_path(input_path, args)
reports.append(
trim_image(
input_path,
output_path,
tolerance=max(0, args.tolerance),
padding=max(0, args.padding),
overwrite=args.overwrite,
)
)
print(json.dumps({"images": reports}, indent=2))
return 0
if __name__ == "__main__":
raise SystemExit(main())
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| 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: 198k | Updated | Claude CodeCodex | Verified | Install |
| 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: 198k | Updated | Claude CodeCodex | Verified | Install |
| 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: 198k | Updated | Claude CodeCodex | Verified | Install |
| 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: 198k | Updated | Claude CodeCodex | Verified | Install |