Skip to content

Commit

Permalink
Fix IOError: cannot write mode RGBA as JPEG
Browse files Browse the repository at this point in the history
  • Loading branch information
avoinea committed Sep 27, 2019
1 parent fe87f86 commit 6105ceb
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/plone/app/imaging/monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ def scale(self, data, w, h, default_format='PNG'):
# for GIF, could also use image.format in ('GIF','PNG')
if original_mode == 'P' and img_format == 'GIF':
image = image.convert('P')

# Avoid - IOError: cannot write mode RGBA as JPEG
# See https://github.com/python-pillow/Pillow/issues/2609#issuecomment-313841918
if original_mode in ('CMYK', 'RGBA', 'LA') and target_format in ('JPG', 'JPEG'):
target_format = 'PNG'

thumbnail_file = StringIO()
# quality parameter doesn't affect lossless formats
image.save(thumbnail_file, target_format, quality=pil_quality, progressive=True)
Expand Down

0 comments on commit 6105ceb

Please sign in to comment.