wagtail / Willow

A wrapper that combines the functionality of multiple Python image libraries into one API
https://willow.wagtail.org/
BSD 3-Clause "New" or "Revised" License
273 stars 53 forks source link

Tests failing with IOError: cannot write mode RGBA as JPEG #60

Closed mans0954 closed 6 years ago

mans0954 commented 6 years ago
python2.7 -m unittest discover -v
...
test_save_as_jpeg (tests.test_pillow.TestPillowOperations) ... ERROR
test_save_as_jpeg_optimised (tests.test_pillow.TestPillowOperations) ... ERROR
test_save_as_jpeg_progressive (tests.test_pillow.TestPillowOperations) ... ERROR
test_save_as_png (tests.test_pillow.TestPillowOperations) ... ok
test_save_as_png_optimised (tests.test_pillow.TestPillowOperations) ... ok
test_save_transparent_gif (tests.test_pillow.TestPillowOperations) ... ok
test_transparent_gif (tests.test_pillow.TestPillowOperations) ... ok

======================================================================
ERROR: test_save_as_jpeg (tests.test_pillow.TestPillowOperations)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/test_pillow.py", line 31, in test_save_as_jpeg
    return_value = self.image.save_as_jpeg(output)
  File "willow/plugins/pillow.py", line 74, in save_as_jpeg
    image.save(f, 'JPEG', quality=quality, **kwargs)
  File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1893, in save
    save_handler(self, fp, filename)
  File "/usr/lib/python2.7/dist-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

======================================================================
ERROR: test_save_as_jpeg_optimised (tests.test_pillow.TestPillowOperations)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/test_pillow.py", line 39, in test_save_as_jpeg_optimised
    unoptimised = self.image.save_as_jpeg(io.BytesIO())
  File "willow/plugins/pillow.py", line 74, in save_as_jpeg
    image.save(f, 'JPEG', quality=quality, **kwargs)
  File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1893, in save
    save_handler(self, fp, filename)
  File "/usr/lib/python2.7/dist-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

======================================================================
ERROR: test_save_as_jpeg_progressive (tests.test_pillow.TestPillowOperations)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/test_pillow.py", line 46, in test_save_as_jpeg_progressive
    image = self.image.save_as_jpeg(io.BytesIO(), progressive=True)
  File "willow/plugins/pillow.py", line 74, in save_as_jpeg
    image.save(f, 'JPEG', quality=quality, **kwargs)
  File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1893, in save
    save_handler(self, fp, filename)
  File "/usr/lib/python2.7/dist-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

----------------------------------------------------------------------
Ran 92 tests in 1.376s

FAILED (errors=3, expected failures=7)

This is with pillow 4.2.1 installed. I believe this is due to an intentional change of behaviour in pillow 4.2.0 and newer:

https://github.com/python-pillow/Pillow/blob/master/docs/releasenotes/4.2.0.rst#removed-deprecated-items

kaedroho commented 6 years ago

Thanks for reporting! I'll have a go at fixing this