diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 76ea48510..6dee3fe23 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -1128,7 +1128,10 @@ class Image: del new_im.info["transparency"] if trns is not None: try: - new_im.info["transparency"] = new_im.palette.getcolor(trns, new_im) + new_im.info["transparency"] = new_im.palette.getcolor( + cast(Tuple[int, int, int], trns), # trns was converted to RGB + new_im, + ) except Exception: # if we can't make a transparent color, don't leave the old # transparency hanging around to mess us up. @@ -1178,7 +1181,10 @@ class Image: if trns is not None: if new_im.mode == "P": try: - new_im.info["transparency"] = new_im.palette.getcolor(trns, new_im) + new_im.info["transparency"] = new_im.palette.getcolor( + cast(Tuple[int, int, int], trns), # trns was converted to RGB + new_im, + ) except ValueError as e: del new_im.info["transparency"] if str(e) != "cannot allocate more than 256 colors":