mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 01:16:16 +03:00
return implicit RGBA to JPEG save, raise warning
This commit is contained in:
parent
c1da18e0ad
commit
193c756139
|
@ -534,6 +534,7 @@ RAWMODE = {
|
|||
"1": "L",
|
||||
"L": "L",
|
||||
"RGB": "RGB",
|
||||
"RGBA": "RGB",
|
||||
"RGBX": "RGB",
|
||||
"CMYK": "CMYK;I", # assume adobe conventions
|
||||
"YCbCr": "YCbCr",
|
||||
|
@ -582,6 +583,14 @@ def _save(im, fp, filename):
|
|||
except KeyError:
|
||||
raise IOError("cannot write mode %s as JPEG" % im.mode)
|
||||
|
||||
if im.mode == 'RGBA':
|
||||
warnings.warn(
|
||||
'You are saving RGBA image as JPEG. The alpha channel will be '
|
||||
'discarded. This conversion is deprecated and will be disabled '
|
||||
'in Pillow 3.7. Please, convert the image to RGB explicitly.',
|
||||
DeprecationWarning
|
||||
)
|
||||
|
||||
info = im.encoderinfo
|
||||
|
||||
dpi = info.get("dpi", (0, 0))
|
||||
|
|
|
@ -99,7 +99,7 @@ class PillowTestCase(unittest.TestCase):
|
|||
" average pixel value difference %.4f > epsilon %.4f" % (
|
||||
ave_diff, epsilon))
|
||||
|
||||
def assert_warning(self, warn_class, func):
|
||||
def assert_warning(self, warn_class, func, *args, **kwargs):
|
||||
import warnings
|
||||
|
||||
result = None
|
||||
|
@ -108,7 +108,7 @@ class PillowTestCase(unittest.TestCase):
|
|||
warnings.simplefilter("always")
|
||||
|
||||
# Hopefully trigger a warning.
|
||||
result = func()
|
||||
result = func(*args, **kwargs)
|
||||
|
||||
# Verify some things.
|
||||
self.assertGreaterEqual(len(w), 1)
|
||||
|
|
|
@ -457,12 +457,18 @@ class TestFileJpeg(PillowTestCase):
|
|||
img.save(out, "JPEG")
|
||||
|
||||
def test_save_wrong_modes(self):
|
||||
# ref https://github.com/python-pillow/Pillow/issues/2005
|
||||
out = BytesIO()
|
||||
for mode in ['LA', 'La', 'RGBA', 'RGBa', 'P']:
|
||||
for mode in ['LA', 'La', 'RGBa', 'P']:
|
||||
img = Image.new(mode, (20, 20))
|
||||
self.assertRaises(IOError, img.save, out, "JPEG")
|
||||
|
||||
def test_save_modes_with_warnings(self):
|
||||
# ref https://github.com/python-pillow/Pillow/issues/2005
|
||||
out = BytesIO()
|
||||
for mode in ['RGBA']:
|
||||
img = Image.new(mode, (20, 20))
|
||||
self.assert_warning(DeprecationWarning, img.save, out, "JPEG")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue
Block a user