@@ -1619,10 +1619,10 @@ def putdata(self, data, scale=1.0, offset=0.0):
16191619
16201620 def putpalette (self , data , rawmode = "RGB" ):
16211621 """
1622- Attaches a palette to this image. The image must be a "P" or
1623- "L" image, and the palette sequence must contain 768 integer
1624- values, where each group of three values represent the red,
1625- green, and blue values for the corresponding pixel
1622+ Attaches a palette to this image. The image must be a "P",
1623+ "PA", " L" or "LA" image, and the palette sequence must contain
1624+ 768 integer values, where each group of three values represent
1625+ the red, green, and blue values for the corresponding pixel
16261626 index. Instead of an integer sequence, you can use an 8-bit
16271627 string.
16281628
@@ -1631,7 +1631,7 @@ def putpalette(self, data, rawmode="RGB"):
16311631 """
16321632 from . import ImagePalette
16331633
1634- if self .mode not in ("L" , "P " ):
1634+ if self .mode not in ("L" , "LA" , "P" , "PA " ):
16351635 raise ValueError ("illegal image mode" )
16361636 self .load ()
16371637 if isinstance (data , ImagePalette .ImagePalette ):
@@ -1643,7 +1643,7 @@ def putpalette(self, data, rawmode="RGB"):
16431643 else :
16441644 data = "" .join (chr (x ) for x in data )
16451645 palette = ImagePalette .raw (rawmode , data )
1646- self .mode = "P"
1646+ self .mode = "PA" if "A" in self . mode else " P"
16471647 self .palette = palette
16481648 self .palette .mode = "RGB"
16491649 self .load () # install new palette
0 commit comments