#215·GLM-OCR

png图片输入无法保存出jpg / RGBA images fail to save as JPEG

Author: Maigic-AICreated May 16, 2026Updated Aug 26, 2026

System Info / 系統信息

  • OS: Windows 11 Pro 10.0.26200
  • Python: 3.12
  • glmocr version: v0.1.5
  • Source image format: PNG with alpha channel (RGBA)

Who can help? / 谁可以帮助到您?

No response

Information / 问题信息

  • The official example scripts / 官方的示例脚本
  • My own modified scripts / 我自己修改的脚本和任务

Reproduction / 复现过程

  1. Prepare a PNG image with alpha channel (RGBA mode) as input
  2. Run:
bash
glmocr parse ./test.png --config ./config.yaml
  1. The pipeline processes the image successfully but fails when saving cropped image regions:
Failed to save image cropped_page0_idx1.jpg: cannot write mode RGBA as JPEG                                                                                                                                                      
Image

The error occurs at glmocr/parser_result/base.py L121 where img.save() is called. When the source image is PNG with alpha channel, cropped regions retain RGBA mode. Since PIL cannot write RGBA images as JPEG, the save fails.

Expected behavior / 期待表现

Cropped image regions should be saved as JPEG files successfully regardless of the source image format (PNG with alpha, PNG without alpha, etc.). RGBA images should be converted to RGB before saving as JPEG.

Fix: #214