Yuan1z0825/nature-skills / skills/nature-image2ppt
nature-image2ppt
FlaggedReconstruct slide images, screenshots, scanned PDFs, or image-only PPTX files as object-level editable PowerPoint. Use for 图片转可编辑PPT、截图还原PPT and diagram reconstruction; not authoring a new deck from research notes.
cli/image2ppt/runtime/_page_artifacts.py
View on GitHubimport json
import shutil
import subprocess
import sys
from pathlib import Path
from deck_run_state import resolve_inside
from split_alpha_components import parse_names as parse_asset_names
SCRIPT_DIR = Path(__file__).resolve().parent
def run(command):
print("+ " + " ".join(str(part) for part in command), flush=True)
subprocess.run([str(part) for part in command], check=True)
def resolve_input_path(page_dir, value):
raw = Path(value).expanduser()
if raw.is_absolute() or raw.drive:
return raw.resolve()
try:
return resolve_inside(page_dir, raw)
except ValueError as exc:
raise SystemExit(
f"Relative input path must stay inside page_dir: {value}"
) from exc
def resolve_output_path(page_dir, value):
raw = Path(value).expanduser()
if raw.is_absolute() or raw.drive:
raise SystemExit(f"Output path must be relative to page_dir: {value}")
try:
return resolve_inside(page_dir, raw)
except ValueError as exc:
raise SystemExit(f"Output path must stay inside page_dir: {value}") from exc
def imagegen_chroma_helper():
helper = SCRIPT_DIR / "remove_chroma_key.py"
if not helper.exists():
raise SystemExit(f"Missing chroma helper: {helper}")
return helper
def process_asset_sheet(args, page_dir):
parse_asset_names(args.asset_names, "--asset-names")
chroma = resolve_output_path(page_dir, args.chroma)
alpha = resolve_output_path(page_dir, args.alpha)
assets_dir = resolve_output_path(page_dir, args.assets_dir)
split_manifest = resolve_output_path(page_dir, args.split_manifest)
if not args.asset_sheet_source and not chroma.exists() and not alpha.exists():
return
if not args.asset_sheet_source and args.skip_chroma and args.skip_split:
return
if not args.skip_chroma and alpha.exists() and not args.force_chroma:
raise SystemExit(f"Output already exists: {alpha} (use --force-chroma to overwrite)")
if args.asset_sheet_source:
source = resolve_input_path(page_dir, args.asset_sheet_source)
if not source.exists():
raise SystemExit(f"Asset sheet source does not exist: {source}")
chroma.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(source, chroma)
print(f"Wrote {chroma}")
if not args.skip_chroma:
if not chroma.exists():
raise SystemExit(f"Chroma input does not exist: {chroma}")
command = [
sys.executable,
imagegen_chroma_helper(),
"--input",
chroma,
"--out",
alpha,
"--auto-key",
"border",
"--soft-matte",
"--transparent-threshold",
args.transparent_threshold,
"--opaque-threshold",
args.opaque_threshold,
]
if args.despill:
command.append("--despill")
if args.force_chroma:
command.append("--force")
run(command)
if args.skip_split:
return
if not alpha.exists():
raise SystemExit(f"Alpha sheet does not exist: {alpha}")
command = [
sys.executable,
SCRIPT_DIR / "split_alpha_components.py",
"--input",
alpha,
"--out-dir",
assets_dir,
"--sort",
args.split_sort,
"--min-area",
args.split_min_area,
"--merge-gap",
args.split_merge_gap,
"--merge-union-growth",
args.split_merge_union_growth,
"--manifest",
split_manifest,
]
if args.square_assets:
command.append("--square")
if args.asset_names:
command.extend(["--names", args.asset_names])
run(command)
def fit_image(image, size):
if image.size == size:
return image
return image.resize(size)
def write_pair(source_path, preview_path, out_path):
from PIL import Image, ImageDraw
source = Image.open(source_path).convert("RGB")
rebuilt = Image.open(preview_path).convert("RGB")
source = fit_image(source, rebuilt.size)
label_h = 32
gap = 18
width, height = rebuilt.size
canvas = Image.new("RGB", (width * 2 + gap, height + label_h), "#f5f7fb")
canvas.paste(source, (0, label_h))
canvas.paste(rebuilt, (width + gap, label_h))
draw = ImageDraw.Draw(canvas)
draw.text((10, 9), "origin", fill="black")
draw.text((width + gap + 10, 9), "preview", fill="black")
out_path.parent.mkdir(parents=True, exist_ok=True)
canvas.save(out_path)
print(f"Wrote {out_path}")
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 |