From 6a9960e8c1960879fe3fb1c3afc143d0899213f5 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 25 Nov 2025 23:40:34 +1100 Subject: [PATCH] Only update Python palette if rawmode was different to the mode --- src/PIL/Image.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 9d50812eb..dc51860a0 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -897,7 +897,9 @@ class Image: else: self.im.putpalettealphas(self.info["transparency"]) self.palette.mode = "RGBA" - else: + elif self.palette.mode != mode: + # If the palette rawmode is different to the mode, + # then update the Python palette data self.palette.palette = self.im.getpalette( self.palette.mode, self.palette.mode )