From c6caff90a128db8028240a2d7e24919cbabb26d7 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Tue, 3 Sep 2019 23:46:25 -0700 Subject: [PATCH] optimize: only re-insert pngs after pngquant Previously we attempted to reinsert all PNGs, but it appears to be unlikely that Leptonica's API is actually capable of optimizing the PNG before it inserts it. In any event qpdf has gained image optimization capabilities as well which we coudld borrow. --- src/ocrmypdf/optimize.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ocrmypdf/optimize.py b/src/ocrmypdf/optimize.py index 9ed26d9f..5358bd17 100644 --- a/src/ocrmypdf/optimize.py +++ b/src/ocrmypdf/optimize.py @@ -346,6 +346,7 @@ def transcode_jpegs(pike, jpegs, root, log, options): def transcode_pngs(pike, images, image_name_fn, root, log, options): + modified = set() if options.optimize >= 2: png_quality = ( max(10, options.png_quality - 10), @@ -366,6 +367,7 @@ def transcode_pngs(pike, images, image_name_fn, root, log, options): png_quality[1], ) ) + modified.add(xref) with tqdm( desc="PNGs", total=len(futures), @@ -375,7 +377,7 @@ def transcode_pngs(pike, images, image_name_fn, root, log, options): for _future in concurrent.futures.as_completed(futures): pbar.update() - for xref in images: + for xref in modified: im_obj = pike.get_object(xref, 0) try: compdata = leptonica.CompressedData.open(png_name(root, xref))