@@ -1443,9 +1443,9 @@ def _save(
14431443 palette_bytes += b"\0 "
14441444 chunk (fp , b"PLTE" , palette_bytes )
14451445
1446- transparency = im .encoderinfo .get ("transparency" , im .info .get ("transparency" , None ))
1446+ transparency = im .encoderinfo .get ("transparency" , im .info .get ("transparency" ))
14471447
1448- if transparency or transparency == 0 :
1448+ if transparency is not None :
14491449 if im .mode == "P" :
14501450 # limit to actual palette size
14511451 alpha_bytes = colors
@@ -1461,17 +1461,15 @@ def _save(
14611461 elif im .mode == "RGB" :
14621462 red , green , blue = transparency
14631463 chunk (fp , b"tRNS" , o16 (red ) + o16 (green ) + o16 (blue ))
1464- else :
1465- if "transparency" in im .encoderinfo :
1466- # don't bother with transparency if it's an RGBA
1467- # and it's in the info dict. It's probably just stale.
1468- msg = "cannot use transparency for this mode"
1469- raise OSError (msg )
1470- else :
1471- if im .mode == "P" and im .im .getpalettemode () == "RGBA" :
1472- alpha = im .im .getpalette ("RGBA" , "A" )
1473- alpha_bytes = colors
1474- chunk (fp , b"tRNS" , alpha [:alpha_bytes ])
1464+ elif im .encoderinfo .get ("transparency" ) is not None :
1465+ # don't bother with transparency if it's an RGBA
1466+ # and it's in the info dict. It's probably just stale.
1467+ msg = "cannot use transparency for this mode"
1468+ raise OSError (msg )
1469+ elif im .mode == "P" and im .im .getpalettemode () == "RGBA" :
1470+ alpha = im .im .getpalette ("RGBA" , "A" )
1471+ alpha_bytes = colors
1472+ chunk (fp , b"tRNS" , alpha [:alpha_bytes ])
14751473
14761474 if dpi := im .encoderinfo .get ("dpi" ):
14771475 chunk (
0 commit comments