You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Saving without any exceptions (was working in 4.1.1 version)
What actually happened?
File /usr/lib/python3.6/site-packages/PIL/Image.py, line 1893, in save
save_handler(self, fp, filename)
File /usr/lib/python3.6/site-packages/PIL/JpegImagePlugin.py, line 604, in _save
raise IOError(cannot write mode %s as JPEG % im.mode)
OSError: cannot write mode RGBA as JPEG
What versions of Pillow and Python are you using?
4.2.0 (with 4.1.1 works properly) / Python 3.6
Please include code that reproduces the issue and whenever possible, an image that demonstrates the issue. Please upload images to GitHub, not to third-party file hosting sites. If necessary, add the image to a zip or tar archive.
The best reproductions are self-contained scripts with minimal dependencies. If you are using a framework such as plone, Django, or buildout, try to replicate the issue just using Pillow.
If it's got an alpha channel that you want to preserve, PNG is really the only reasonable choice. Alternately you can flatten it to a RGB image and save as a JPEG.
Reacted by Wayne Polatkan, Olaide Ojewale, jtlz2, LexRillo, FooBar167, Ed Summers, Alex Ellis and Francois Vieux
@AymericHENRY Hi. While this is just reiterating what has already been said, you should have no problem saving an image in RGBA mode to PNG. To save an image in RGBA mode as JPEG means getting rid of the alpha channel, because JPEG doesn't transparency. So, if you have an image in RGBA mode, then converting it to RGB will let you save it as JPEG.
In most cases the discarding the alpha channel will give you undesirable result, because transparent pixels also have some unpredictable colors. It is much better to fill transparent pixels with certain color:
Reacted by Cal Bryant, Steve Kossouho, tuchang, Raymond, Eduardo Henrique Vieira dos Santos, Sean Bendtsen Powell, bdpothik, Addison Schiller, Mark Feeney, Evgeny Fadeev and 57 more
Reacted by nourhan-massoud and norohind
Reacted by Ignacio Iglesias, AlanJoygit, micsikz, Jean-Sébastien Gosselin, Pavel Martynov and norohind
Activity
wiredfool commentedon Jul 4, 2017
Yep: https://github.com/python-pillow/Pillow/blob/master/docs/releasenotes/4.2.0.rst#removed-deprecated-items
JPEGs can't represent an alpha channel. It's been issuing a warning for a while, removed in this release.
karolpawlowski commentedon Jul 4, 2017
Thanks @wiredfool ! What is preferred way to make it works with both PNG and JPEG files?
wiredfool commentedon Jul 4, 2017
If it's got an alpha channel that you want to preserve, PNG is really the only reasonable choice. Alternately you can flatten it to a
RGBimage and save as a JPEG.radarhere commentedon Jul 8, 2017
@AymericHENRY Hi. While this is just reiterating what has already been said, you should have no problem saving an image in RGBA mode to PNG. To save an image in RGBA mode as JPEG means getting rid of the alpha channel, because JPEG doesn't transparency. So, if you have an image in RGBA mode, then converting it to RGB will let you save it as JPEG.
homm commentedon Jul 9, 2017
In most cases the discarding the alpha channel will give you undesirable result, because transparent pixels also have some unpredictable colors. It is much better to fill transparent pixels with certain color:
Fix RGBA vs RGB issue.
Fix issue "cannot write mode RGBA as JPEG"
Fix issue "cannot write mode RGBA as JPEG" (#19)
Ensure Pillow <4.2 for testing 0.13
Fixed issue with deprecated Pillow behavior
Issue webcompat#1942 - Converts PNG images to RGB to remove the Alpha…
Fix script for generating overviews
Fix script for generating overviews
Convert RGBA to RGB by layering image on a black background
Revert "Test: /api/image/ returns jpeg image"
fix ipynbplotutils.Plot3D
Restore fast mesa display (#110)