From eb8eea9991bca2faab8b19dcfd848e3437beb211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dieter=20Schl=C3=BCter?= Date: Fri, 2 Oct 2026 00:47:42 +0200 Subject: [PATCH] =?UTF-8?q?Bilder=20standardm=C3=A4=C3=9Fig=20als=20JPEG?= =?UTF-8?q?=20(--image-format),=20Output/=20ignorieren?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit EPUB Band 1: 12,9 MB -> 5,0 MB, Band 2: 14,3 MB -> 5,3 MB. Co-Authored-By: Claude Opus 5.5 --- .gitignore | 3 +++ pdf2md_v5.py | 11 +++++++++-- tests/test_e2e.py | 11 ++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 63ddfa1..7a9b5da 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,6 @@ __pycache__/ # Leere Datei durch System-Bug /3 + +# Ergebnisse zum Ansehen +Output/ diff --git a/pdf2md_v5.py b/pdf2md_v5.py index 6f7da8c..5c134f3 100644 --- a/pdf2md_v5.py +++ b/pdf2md_v5.py @@ -805,7 +805,7 @@ def convert_pages(source: str, run: str, pages: list[int], options: dict) -> str footer=options["keep_footers"], write_images=options["images"], image_path=options["image_path"], - image_format="png", + image_format=options["image_format"], ) if run == RUN_OCR: kwargs.update( @@ -984,6 +984,12 @@ def main() -> int: action="store_true", 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( "--epub", action="store_true", @@ -1057,7 +1063,7 @@ def main() -> int: if args.images: image_dir.mkdir(parents=True, exist_ok=True) if epub_path: - cover = image_dir / "cover.png" + cover = image_dir / f"cover.{args.image_format}" doc[0].get_pixmap(dpi=150).save(cover) options = dict( @@ -1065,6 +1071,7 @@ def main() -> int: keep_footers=args.keep_footers, images=args.images, image_path=str(image_dir.resolve()) if args.images else "", + image_format=args.image_format, ocr_language=args.ocr_language, ocr_dpi=args.ocr_dpi, ) diff --git a/tests/test_e2e.py b/tests/test_e2e.py index e0ca5da..65ce0a9 100644 --- a/tests/test_e2e.py +++ b/tests/test_e2e.py @@ -110,7 +110,9 @@ def test_epub(pdfs, tmp_path): out = tmp_path / "buch.md" run(pdfs["digital"], out, "--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: assert z.read("mimetype") == b"application/epub+zip" nav = z.read("EPUB/nav.xhtml").decode() @@ -119,3 +121,10 @@ def test_epub(pdfs, tmp_path): assert title in nav assert "Erika Muster" 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)