Comment 6 for bug 381379

Revision history for this message
Stani (stani) wrote :

$ 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.