Fix: convert crops PNG cannot store before handing them to tesseract

This commit is contained in:
stumpylog committed 2026-11-20 11:24:06 -08:00
1 parent ad5a7b365e
commit a2c18123fa
2 files changed
+51

No files matched your search

+3
View File
@@ -801,6 +801,9 @@ def _read_barcode(cropped: Image.Image, zone_name: str) -> str | None:
def _ocr_text(cropped: Image.Image, zone: OcrTemplateZone, tmp_dir: Path) -> str | None:
"""OCR a cropped image with Tesseract."""
crop_path = tmp_dir / f"zone_{zone.pk}.png"
# PNG cannot store every mode (e.g. CMYK from a CMYK JPEG or TIFF), so convert the others to RGB.
if cropped.mode not in ("1", "L", "LA", "P", "RGB", "RGBA", "I;16", "I;16B"):
cropped = cropped.convert("RGB")
cropped.save(crop_path)
try: