Compare commits
5 Commits
1.1.3
...
0338fd6524
| Author | SHA1 | Date | |
|---|---|---|---|
| 0338fd6524 | |||
| 85876228eb | |||
| f498cafdf3 | |||
| f0d07dab4b | |||
| de9c9ad48c |
@@ -1,6 +1,6 @@
|
||||
|
||||
# PPTX Image Compressor (CaesiumCLT only)
|
||||
**Version 1.1.3**
|
||||
**Version 1.1.4**
|
||||
|
||||
Dieses Paket enthält:
|
||||
|
||||
@@ -32,14 +32,13 @@ Die Batch lädt bei Bedarf automatisch das **Windows Embeddable Python Package**
|
||||
|
||||
## Was das Tool macht
|
||||
- Entpackt die PPTX in einen Temp‑Ordner
|
||||
- Komprimiert **JPG/JPEG, PNG, WebP** mit **CaesiumCLT** (Default `-q 90`, `-O bigger`)
|
||||
- Komprimiert **JPG/JPEG, PNG, WebP, GIF** mit **CaesiumCLT** (Default `-q 90`, `-O bigger`)
|
||||
- Ersetzt Bilder nur, wenn die komprimierte Datei kleiner ist
|
||||
- Schreibt ein CSV‑Log (`.log` neben der Output‑PPTX)
|
||||
- Baut eine neue PPTX und zeigt eine Summary (Name, Größe vorher/nachher, Ersparnis %, Zeit)
|
||||
- Räumt alle temporären Dateien auf (keine Caesium‑Tempfiles in der finalen PPTX)
|
||||
|
||||
## Hinweise
|
||||
- **GIF** wird übersprungen (keine Rekodierung).
|
||||
- `-t` steuert die Parallelität der Python‑Threads; intern wird `caesiumclt --threads 1` gesetzt, sobald `-t > 1`, um Oversubscription zu vermeiden. Default ist 16
|
||||
- `-q` steuert das Qualitätslevel; intern wird `caesiumclt -q` mit diesem Wert von `0..100` benutzt, Default ist 90
|
||||
- Die Batch **verwendet bevorzugt das Embeddable Python** neben der BAT; ansonsten sucht sie echte `python.exe`/`py.exe` im PATH, **ignoriert** aber die Microsoft‑Store‑Alias‑Pfade (`WindowsApps`).
|
||||
|
||||
Binary file not shown.
@@ -12,7 +12,7 @@ set "SELF_DIR=%~dp0"
|
||||
set "SCRIPT=%SELF_DIR%pptx_image_compress.py"
|
||||
|
||||
rem ---- Python Embeddable config ----
|
||||
set "PY_EMBED_VERSION=3.13.7"
|
||||
set "PY_EMBED_VERSION=3.14.4"
|
||||
set "PY_EMBED_ZIP=python-%PY_EMBED_VERSION%-embed-amd64.zip"
|
||||
set "PY_EMBED_URL=https://www.python.org/ftp/python/%PY_EMBED_VERSION%/%PY_EMBED_ZIP%"
|
||||
set "PY_DIR=%SELF_DIR%python-embed"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
PPTX Grafik-Komprimier-Tool (nur CaesiumCLT, Multi-Thread, Batch, sauberes Cleanup)
|
||||
Version: 1.1.3
|
||||
Version: 1.1.4
|
||||
|
||||
|
||||
Highlights:
|
||||
@@ -12,12 +12,14 @@ Highlights:
|
||||
- Log: image_name,size_before,size_after,saving,saving_percent
|
||||
- Summary inkl. Zeit benötigt
|
||||
|
||||
Änderungen in 1.1.3:
|
||||
- Changed all UNICODE Chars to ASCII
|
||||
Änderungen in 1.1.4:
|
||||
- Libcaesium 1.1.0 kann nun auch gif verkleinern
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
import xml.etree.ElementTree as ET
|
||||
import sys
|
||||
import zipfile
|
||||
import tempfile
|
||||
@@ -30,10 +32,12 @@ from pathlib import Path
|
||||
from datetime import timedelta
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
from threading import Lock
|
||||
from typing import List, Optional
|
||||
|
||||
__version__ = "1.1.3"
|
||||
|
||||
ALLOWED_EXT = {".jpg", ".jpeg", ".png", ".webp", ".gif"} # GIF wird übersprungen
|
||||
__version__ = "1.1.4"
|
||||
|
||||
ALLOWED_EXT = {".jpg", ".jpeg", ".png", ".webp", ".gif"}
|
||||
PROGRESS_BAR_LEN = 40
|
||||
TEMP_PREFIX = "pptx_compress_"
|
||||
|
||||
@@ -91,7 +95,7 @@ def compress_with_caesium(original: Path, out_dir: Path, caesium_threads: int |
|
||||
raise RuntimeError("[ERROR] 'caesiumclt' wurde nicht gefunden. Bitte CaesiumCLT installieren und in PATH verfügbar machen.")
|
||||
out_dir.mkdir(parents=True, exist_ok=True)
|
||||
ext = original.suffix.lower()
|
||||
if ext not in {".jpg", ".jpeg", ".png", ".webp"}:
|
||||
if ext not in {".jpg", ".jpeg", ".png", ".webp", ".gif"}:
|
||||
return None
|
||||
cmd = [exe, "-q", str(quality), "-O", "bigger", "-o", str(out_dir)]
|
||||
if caesium_threads is not None:
|
||||
@@ -117,6 +121,38 @@ def format_duration(seconds: float) -> str:
|
||||
return f"{hms}.{frac[:2]}"
|
||||
return base
|
||||
|
||||
def get_slide_numbers_for_image(rels_dir: str, image_filename: str) -> Optional[List[int]]:
|
||||
"""
|
||||
Durchsucht alle .rels-Dateien im angegebenen Verzeichnis und gibt die Slide-Nummern zurück,
|
||||
in denen die angegebene Bilddatei referenziert wird.
|
||||
|
||||
:param rels_dir: Pfad zum Verzeichnis ppt/slides/_rels
|
||||
:param image_filename: z. B. 'image80.png'
|
||||
:return: Liste von Slide-Nummern oder None
|
||||
"""
|
||||
slide_numbers = []
|
||||
|
||||
for rels_file in os.listdir(rels_dir):
|
||||
if rels_file.startswith("slide") and rels_file.endswith(".xml.rels"):
|
||||
rels_path = os.path.join(rels_dir, rels_file)
|
||||
try:
|
||||
tree = ET.parse(rels_path)
|
||||
root = tree.getroot()
|
||||
for rel in root.findall(".//{http://schemas.openxmlformats.org/package/2006/relationships}Relationship"):
|
||||
target = rel.attrib.get("Target", "")
|
||||
if image_filename in target:
|
||||
match = re.search(r"slide(\d+).xml.rels", rels_file)
|
||||
if match:
|
||||
slide_number = int(match.group(1))
|
||||
slide_numbers.append(slide_number)
|
||||
except ET.ParseError:
|
||||
print(f"Fehler beim Parsen von {rels_file}")
|
||||
|
||||
return slide_numbers if slide_numbers else None
|
||||
|
||||
|
||||
|
||||
|
||||
# -------------------- Core per-deck processing --------------------
|
||||
def process_single_deck(input_pptx: Path, output_pptx: Path, threads: int, quality: int) -> dict:
|
||||
start_time = time.perf_counter()
|
||||
@@ -143,7 +179,7 @@ def process_single_deck(input_pptx: Path, output_pptx: Path, threads: int, quali
|
||||
|
||||
log_file = output_pptx.with_suffix(".log.csv")
|
||||
ensure_clean_file(log_file)
|
||||
log_lines = ["image_name;size_before(kb);size_after(kb);saving(kb);saving_percent(%)\n"]
|
||||
log_lines = ["image_name;size_before(kb);size_after(kb);saving(kb);saving_percent(%);in_slide_number\n"]
|
||||
|
||||
size_before = input_pptx.stat().st_size
|
||||
result["size_before"] = size_before
|
||||
@@ -151,8 +187,11 @@ def process_single_deck(input_pptx: Path, output_pptx: Path, threads: int, quali
|
||||
with zipfile.ZipFile(input_pptx, "r") as z:
|
||||
z.extractall(work_dir)
|
||||
|
||||
slides_dir = work_dir / "ppt" / "slides"
|
||||
media_dir = work_dir / "ppt" / "media"
|
||||
|
||||
images = []
|
||||
|
||||
if media_dir.exists():
|
||||
for f in sorted(media_dir.iterdir()):
|
||||
if f.is_file() and f.suffix.lower() in ALLOWED_EXT:
|
||||
@@ -173,14 +212,16 @@ def process_single_deck(input_pptx: Path, output_pptx: Path, threads: int, quali
|
||||
nonlocal done_count
|
||||
ext = img_path.suffix.lower()
|
||||
orig_size = img_path.stat().st_size
|
||||
if ext == ".gif":
|
||||
with lock:
|
||||
done_count += 1
|
||||
log_lines.append(f"{img_path.name};{human_kb(orig_size)};{human_kb(orig_size)};0;0.0\n")
|
||||
print_progress(done_count, total)
|
||||
return
|
||||
chosen_size = orig_size
|
||||
found_in_slide=None
|
||||
slide_nr=""
|
||||
|
||||
try:
|
||||
found_in_slide = get_slide_numbers_for_image(slides_dir.name, img_path.name)
|
||||
if found_in_slide is None:
|
||||
slide_nr = "NOT_USED"
|
||||
else:
|
||||
slide_nr = str(found_in_slide)
|
||||
out_sub = scratch_dir / f"img_{idx:06d}"
|
||||
caesium_out = compress_with_caesium(img_path, out_sub, caesium_threads, quality)
|
||||
if caesium_out and caesium_out.exists():
|
||||
@@ -195,8 +236,9 @@ def process_single_deck(input_pptx: Path, output_pptx: Path, threads: int, quali
|
||||
finally:
|
||||
saving = orig_size - chosen_size
|
||||
saving_percent = round((saving / orig_size) * 100, 2) if orig_size > 0 else 0.0
|
||||
|
||||
with lock:
|
||||
log_lines.append(f"{img_path.name};{human_kb(orig_size)};{human_kb(chosen_size)};{human_kb(saving)};{saving_percent}\n")
|
||||
log_lines.append(f"{img_path.name};{human_kb(orig_size)};{human_kb(chosen_size)};{human_kb(saving)};{saving_percent};{slide_nr}\n")
|
||||
done_count += 1
|
||||
print_progress(done_count, total)
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
Place your PPTX files here for testing, or use -i with a full path.
|
||||
Reference in New Issue
Block a user