mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-27 10:26:19 +03:00
Delete transparency info when convert'ing RGB/L to RGBA
info['transparency] was not removed when an RGB or L image was converted to RGBA. This could result in unexpected behavior when saving the resulting image. Other image conversions already delete or update the transparency info. There is a shortcut for RGB/L to RGBA which missed this.
This commit is contained in:
parent
0cd84cf9b3
commit
9e7de70bac
|
@ -877,8 +877,10 @@ class Image(object):
|
||||||
if self.mode in ('L', 'RGB') and mode == 'RGBA':
|
if self.mode in ('L', 'RGB') and mode == 'RGBA':
|
||||||
# Use transparent conversion to promote from transparent
|
# Use transparent conversion to promote from transparent
|
||||||
# color to an alpha channel.
|
# color to an alpha channel.
|
||||||
return self._new(self.im.convert_transparent(
|
new_im = self._new(self.im.convert_transparent(
|
||||||
mode, self.info['transparency']))
|
mode, self.info['transparency']))
|
||||||
|
del(new_im.info['transparency'])
|
||||||
|
return new_im
|
||||||
elif self.mode in ('L', 'RGB', 'P') and mode in ('L', 'RGB', 'P'):
|
elif self.mode in ('L', 'RGB', 'P') and mode in ('L', 'RGB', 'P'):
|
||||||
t = self.info['transparency']
|
t = self.info['transparency']
|
||||||
if isinstance(t, bytes):
|
if isinstance(t, bytes):
|
||||||
|
|
|
@ -122,6 +122,10 @@ class TestImageConvert(PillowTestCase):
|
||||||
self.assertIn('transparency', p.info)
|
self.assertIn('transparency', p.info)
|
||||||
p.save(f)
|
p.save(f)
|
||||||
|
|
||||||
|
p = im.convert('RGBA')
|
||||||
|
self.assertNotIn('transparency', p.info)
|
||||||
|
p.save(f)
|
||||||
|
|
||||||
p = self.assert_warning(
|
p = self.assert_warning(
|
||||||
UserWarning,
|
UserWarning,
|
||||||
lambda: im.convert('P', palette=Image.ADAPTIVE))
|
lambda: im.convert('P', palette=Image.ADAPTIVE))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user