do not allow to save images discarding alpha channel

This commit is contained in:
homm 2016-07-03 05:40:34 +03:00
parent 4f4c982229
commit c1da18e0ad
2 changed files with 13 additions and 1 deletions

View File

@ -534,7 +534,6 @@ RAWMODE = {
"1": "L",
"L": "L",
"RGB": "RGB",
"RGBA": "RGB",
"RGBX": "RGB",
"CMYK": "CMYK;I", # assume adobe conventions
"YCbCr": "YCbCr",

View File

@ -450,6 +450,19 @@ class TestFileJpeg(PillowTestCase):
# Assert
self.assertEqual(im.format, "JPEG")
def test_save_correct_modes(self):
out = BytesIO()
for mode in ['1', 'L', 'RGB', 'RGBX', 'CMYK', 'YCbCr']:
img = Image.new(mode, (20, 20))
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']:
img = Image.new(mode, (20, 20))
self.assertRaises(IOError, img.save, out, "JPEG")
if __name__ == '__main__':
unittest.main()