Skip to content

Commit

Permalink
PIL to Pix: convert all alpha modes to RGBA
Browse files Browse the repository at this point in the history
  • Loading branch information
bertsky authored and sirfz committed Nov 9, 2021
1 parent 9c8740d commit 310ae9a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tesserocr.pyx
Expand Up @@ -329,6 +329,9 @@ cdef unicode _free_str(char *text):
cdef bytes _image_buffer(image):
"""Return raw bytes of a PIL Image"""
with BytesIO() as f:
# Pix and BMP only allow alpha as RGBA:
if image.mode in ['LA', 'PA', 'RGBa', 'La']:
image = image.convert('RGBA')
image.save(f, image.format or 'BMP')
return f.getvalue()
Expand Down

0 comments on commit 310ae9a

Please sign in to comment.