Feature: Allow a user to disable the pixel limit for OCR entirely (#5996)

This commit is contained in:
Trenton H
2024-03-04 14:37:36 -08:00
committed by GitHub
parent 6379e7b54f
commit 6779042242
5 changed files with 40 additions and 15 deletions

View File

@@ -293,20 +293,19 @@ class RasterisedDocumentParser(DocumentParser):
f"they will not be used. Error: {e}",
)
if self.settings.max_image_pixel is not None:
if (
self.settings.max_image_pixel is not None
and self.settings.max_image_pixel >= 0
):
# Convert pixels to mega-pixels and provide to ocrmypdf
max_pixels_mpixels = self.settings.max_image_pixel / 1_000_000.0
if max_pixels_mpixels > 0:
self.log.debug(
f"Calculated {max_pixels_mpixels} megapixels for OCR",
)
ocrmypdf_args["max_image_mpixels"] = max_pixels_mpixels
else:
self.log.warning(
"There is an issue with PAPERLESS_OCR_MAX_IMAGE_PIXELS, "
"this value must be at least 1 megapixel if set",
)
msg = (
"OCR pixel limit is disabled!"
if max_pixels_mpixels == 0
else f"Calculated {max_pixels_mpixels} megapixels for OCR"
)
self.log.debug(msg)
ocrmypdf_args["max_image_mpixels"] = max_pixels_mpixels
return ocrmypdf_args