phatch-dev team mailing list archive
-
phatch-dev team
-
Mailing list archive
-
Message #00043
[Bug 381660] Re: Convert mode from RGBA to P should preserve transparency
$ bzr diff
=== modified file 'phatch/actions/save.py'
--- phatch/actions/save.py 2009-05-29 13:40:01 +0000
+++ phatch/actions/save.py 2009-06-03 03:02:58 +0000
@@ -114,8 +114,11 @@
elif self.is_type(typ,TIF):
compression = self.get_field('TIFF Compression',info)
options['compression.tif'] = compression
- elif self.is_type(typ,GIF) and not(info['transparency'] is None):
- options['transparency'] = info['transparency']
+ elif self.is_type(typ,GIF):
+ photo.convert('P', palette=Image.ADAPTIVE)
+ info = photo.get_info()
+ if not info['transparency'] is None:
+ options['transparency'] = info['transparency']
#save
photo.save(filename, **options)
=== modified file 'phatch/core/pil.py'
--- phatch/core/pil.py 2009-05-29 16:56:48 +0000
+++ phatch/core/pil.py 2009-06-03 02:56:02 +0000
@@ -411,7 +411,17 @@
def convert(self,mode,*args,**keyw):
"""Converts all layers to a different mode."""
for layer in self.layers.values():
- layer.image = layer.image.convert(mode,*args,**keyw)
+ if mode == 'P' and layer.image.mode == 'RGBA':
+ alpha = layer.image.split()[3]
+ layer.image = layer.image.convert('RGB').convert(
+ mode, colors=255, *args, **keyw
+ )
+ layer.image.paste(
+ 255, Image.eval(alpha, lambda a: 255 if a <=128 else 0)
+ )
+ self.info['transparency'] = 255
+ else:
+ layer.image = layer.image.convert(mode,*args,**keyw)
self.set_attr(_t('mode'),mode)
def resize(self,size,method):
$ bzr commit -m "fix gif transparency"
Committing to: /home/stani/sync/python/phatch/trunk/
modified phatch/actions/save.py
modified phatch/core/pil.py
Committed revision 626.
** Changed in: phatch
Status: Confirmed => Fix Committed
--
Convert mode from RGBA to P should preserve transparency
https://bugs.launchpad.net/bugs/381660
You received this bug notification because you are a member of Phatch
Developers, which is subscribed to Phatch.
Status in Phatch = Photo & Batch!: Fix Committed
Bug description:
When converting a RGBA image to a Palette image the transparency is not kept. This should be done by giving an index value to photo.info['transparency'] and the code should be added to the photo.convert method in core/pil.py;
http://bazaar.launchpad.net/~stani/phatch/dev/annotate/head:/phatch/core/pil.py#L389