Convert mode from RGBA to P should preserve transparency

Bug #381660 reported by Stani
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Phatch
Fix Released
High
Nadia Alramli

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

Stani (stani)
Changed in phatch:
assignee: nobody → Nadia Alramli (nadiana)
importance: Undecided → High
status: New → Confirmed
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.

Changed in phatch:
status: Confirmed → Fix Committed
Stani (stani)
Changed in phatch:
milestone: none → 0.2.1
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.