Fix optimize=2/3 crash when using Python API

The jpg_quality and png_quality options default to None in the pydantic
model, but the fallback check only handled == 0. This caused a TypeError
when calling ocrmypdf.ocr() with optimize >= 2 without explicitly
setting quality values. Fixes #1641.
This commit is contained in:
James R. Barlow
2026-03-10 01:51:07 -07:00
parent 59190ef643
commit b588e3bfd7
+2 -2
View File
@@ -681,9 +681,9 @@ def optimize(
safe_symlink(input_file, output_file)
return output_file
if options.jpg_quality == 0:
if not options.jpg_quality:
options.jpg_quality = DEFAULT_JPEG_QUALITY if options.optimize < 3 else 40
if options.png_quality == 0:
if not options.png_quality:
options.png_quality = DEFAULT_PNG_QUALITY if options.optimize < 3 else 30
with Pdf.open(input_file) as pdf: