Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve RGBA image.mode #75

Merged
merged 2 commits into from
Feb 9, 2016
Merged

Preserve RGBA image.mode #75

merged 2 commits into from
Feb 9, 2016

Conversation

z4r
Copy link
Contributor

@z4r z4r commented Jan 10, 2014

No description provided.

@z4r z4r mentioned this pull request Jan 10, 2014
grantmcconnaughey added a commit that referenced this pull request Feb 9, 2016
Preserve RGBA image.mode
@grantmcconnaughey grantmcconnaughey merged commit a6b4c2b into jazzband:master Feb 9, 2016
@grantmcconnaughey
Copy link
Contributor

Merged! Thank you.

@vonmaster
Copy link

Hi,

This pull request is causing an issue OSError: cannot write mode RGBA as JPEG, when uploading a PNG with a RGBA mode. I suggest to revert to the previous state:

if image.mode != "RGB":
    image = image.convert("RGB")

Detail Error Log:

>>> from django.utils import six
>>> thumb = six.BytesIO()
>>> image.save(thumb, settings.AVATAR_THUMB_FORMAT, quality=quality)
Traceback (most recent call last):
  File "/opt/python/run/venv/local/lib64/python3.6/site-packages/PIL/JpegImagePlugin.py", line 611, in _save
    rawmode = RAWMODE[im.mode]
KeyError: 'RGBA'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib64/python3.6/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<console>", line 1, in <module>
  File "/opt/python/run/venv/local/lib64/python3.6/site-packages/PIL/Image.py", line 2151, in save
    save_handler(self, fp, filename)
  File "/opt/python/run/venv/local/lib64/python3.6/site-packages/PIL/JpegImagePlugin.py", line 613, in _save
    raise OSError(f"cannot write mode {im.mode} as JPEG") from e
OSError: cannot write mode RGBA as JPEG
>>> image.mode
'RGBA'
>>> image.mode not in ("RGB", "RGBA")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants