Skip to content

Cannot write JPG images anymore with Pillow 4.2 #9585

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

Closed
ghost opened this issue Oct 26, 2017 · 7 comments
Closed

Cannot write JPG images anymore with Pillow 4.2 #9585

ghost opened this issue Oct 26, 2017 · 7 comments
Milestone

Comments

@ghost
Copy link

ghost commented Oct 26, 2017

Hi,
Due to issue python-pillow/Pillow#2609 , I cannot save anymore my Matplotlib graphs to JPG format (with the alpha layers merged together) since Conda upgraded Pillow to version 4.2. This used to work before:

self._fig.savefig(file_name, dpi=dpi, bbox_inches='tight', bbox_extra_artists=bbox_extra_artists, pad_inches=.4)
File "/path/to/Conda-linux-x64/lib/python2.7/site-packages/matplotlib/figure.py", line 1565, in savefig
self.canvas.print_figure(*args, **kwargs)
File "/path/to/Conda-linux-x64/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 2232, in print_figure
**kwargs)
File "/path/to/Conda-linux-x64/lib/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 583, in print_jpg
return image.save(filename_or_obj, format='jpeg', **options)
File "/path/to/Conda-linux-x64/lib/python2.7/site-packages/PIL/Image.py", line 1893, in save
save_handler(self, fp, filename)
File "/path/to/Conda-linux-x64/lib/python2.7/site-packages/PIL/JpegImagePlugin.py", line 604, in _save
raise IOError("cannot write mode %s as JPEG" % im.mode)
IOError: cannot write mode RGBA as JPEG

Downgrading to Pillow 4.1 (conda install pillow=4.1)makes this code work.
Is it possible to force the merge of the alpha channel before or when writing? Adding , transparent=False to savefig did not help.
I guess that feature python-pillow/Pillow#2663 will fix this problem.
Thanks.

@tacaswell tacaswell added this to the v2.1.1 milestone Oct 26, 2017
@tacaswell
Copy link
Member

What version of Matplotlib?

Something like this went by recently....

@tacaswell
Copy link
Member

@ghost
Copy link
Author

ghost commented Oct 26, 2017

This happens with matplotlib 1.5.1 (python 2.7.14).

@tacaswell
Copy link
Member

Can you try with 2.1?

@anntzer
Copy link
Contributor

anntzer commented Oct 26, 2017

this seems to have been fixed somewhere between 1.5.3 and 2.1

@tacaswell
Copy link
Member

Fixed by #5324 which is included in 2.0

@sebastienaubry Thanks for taking the time to report this. It should work if you update to at least 2.0.

@ghost
Copy link
Author

ghost commented Oct 26, 2017

Hi,
Indeed, it works under 2.1.0.
Thanks

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

No branches or pull requests

2 participants