Bilder standardmäßig als JPEG (--image-format), Output/ ignorieren

EPUB Band 1: 12,9 MB -> 5,0 MB, Band 2: 14,3 MB -> 5,3 MB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dieter Schlüter 2026-10-02 00:47:42 +02:00
commit eb8eea9991
3 changed files with 22 additions and 3 deletions

3
.gitignore vendored
View file

@ -14,3 +14,6 @@ __pycache__/
# Leere Datei durch System-Bug # Leere Datei durch System-Bug
/3 /3
# Ergebnisse zum Ansehen
Output/

View file

@ -805,7 +805,7 @@ def convert_pages(source: str, run: str, pages: list[int], options: dict) -> str
footer=options["keep_footers"], footer=options["keep_footers"],
write_images=options["images"], write_images=options["images"],
image_path=options["image_path"], image_path=options["image_path"],
image_format="png", image_format=options["image_format"],
) )
if run == RUN_OCR: if run == RUN_OCR:
kwargs.update( kwargs.update(
@ -984,6 +984,12 @@ def main() -> int:
action="store_true", action="store_true",
help="Grafiken speichern und in Markdown verlinken", help="Grafiken speichern und in Markdown verlinken",
) )
parser.add_argument(
"--image-format",
choices=["jpg", "png"],
default="jpg",
help="Bildformat: jpg (klein, Standard) oder png (verlustfrei, groß)",
)
parser.add_argument( parser.add_argument(
"--epub", "--epub",
action="store_true", action="store_true",
@ -1057,7 +1063,7 @@ def main() -> int:
if args.images: if args.images:
image_dir.mkdir(parents=True, exist_ok=True) image_dir.mkdir(parents=True, exist_ok=True)
if epub_path: if epub_path:
cover = image_dir / "cover.png" cover = image_dir / f"cover.{args.image_format}"
doc[0].get_pixmap(dpi=150).save(cover) doc[0].get_pixmap(dpi=150).save(cover)
options = dict( options = dict(
@ -1065,6 +1071,7 @@ def main() -> int:
keep_footers=args.keep_footers, keep_footers=args.keep_footers,
images=args.images, images=args.images,
image_path=str(image_dir.resolve()) if args.images else "", image_path=str(image_dir.resolve()) if args.images else "",
image_format=args.image_format,
ocr_language=args.ocr_language, ocr_language=args.ocr_language,
ocr_dpi=args.ocr_dpi, ocr_dpi=args.ocr_dpi,
) )

View file

@ -110,7 +110,9 @@ def test_epub(pdfs, tmp_path):
out = tmp_path / "buch.md" out = tmp_path / "buch.md"
run(pdfs["digital"], out, "--epub") run(pdfs["digital"], out, "--epub")
epub = tmp_path / "buch.epub" epub = tmp_path / "buch.epub"
assert (tmp_path / "buch_images" / "cover.png").is_file() images = tmp_path / "buch_images"
assert (images / "cover.jpg").is_file()
assert {f.suffix for f in images.iterdir()} == {".jpg"}
with zipfile.ZipFile(epub) as z: with zipfile.ZipFile(epub) as z:
assert z.read("mimetype") == b"application/epub+zip" assert z.read("mimetype") == b"application/epub+zip"
nav = z.read("EPUB/nav.xhtml").decode() nav = z.read("EPUB/nav.xhtml").decode()
@ -119,3 +121,10 @@ def test_epub(pdfs, tmp_path):
assert title in nav assert title in nav
assert "Erika Muster" in opf assert "Erika Muster" in opf
assert "cover" in opf assert "cover" in opf
def test_png_on_request(pdfs, tmp_path):
out = tmp_path / "png.md"
run(pdfs["digital"], out, "--images", "--image-format", "png")
md = out.read_text(encoding="utf-8")
assert re.search(r"!\[\]\(png_images/[^)]+\.png\)", md)