diff --git a/src/ocrmypdf/_pipelines/_common.py b/src/ocrmypdf/_pipelines/_common.py index e5ba9725..d3c219e0 100644 --- a/src/ocrmypdf/_pipelines/_common.py +++ b/src/ocrmypdf/_pipelines/_common.py @@ -20,6 +20,7 @@ from pathlib import Path from typing import NamedTuple, cast import PIL +import PIL.Image from pikepdf import Pdf from ocrmypdf._annots import remove_broken_goto_annotations @@ -307,6 +308,11 @@ def setup_pipeline( if not options.jobs: options.jobs = available_cpu_count() + # Apply PIL max image pixels side effect + PIL.Image.MAX_IMAGE_PIXELS = int(options.max_image_mpixels * 1_000_000) + if PIL.Image.MAX_IMAGE_PIXELS == 0: + PIL.Image.MAX_IMAGE_PIXELS = None # type: ignore + pikepdf_enable_mmap() executor = setup_executor(plugin_manager) return executor