mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-14 05:36:48 +03:00
Merge pull request #5859 from radarhere/saving_rgba_gif
When saving RGBA to GIF, make use of first transparent palette entry
This commit is contained in:
commit
f560707def
|
@ -957,3 +957,13 @@ def test_missing_background():
|
||||||
with Image.open("Tests/images/missing_background.gif") as im:
|
with Image.open("Tests/images/missing_background.gif") as im:
|
||||||
im.seek(1)
|
im.seek(1)
|
||||||
assert_image_equal_tofile(im, "Tests/images/missing_background_first_frame.png")
|
assert_image_equal_tofile(im, "Tests/images/missing_background_first_frame.png")
|
||||||
|
|
||||||
|
|
||||||
|
def test_saving_rgba(tmp_path):
|
||||||
|
out = str(tmp_path / "temp.gif")
|
||||||
|
with Image.open("Tests/images/transparent.png") as im:
|
||||||
|
im.save(out)
|
||||||
|
|
||||||
|
with Image.open(out) as reloaded:
|
||||||
|
reloaded_rgba = reloaded.convert("RGBA")
|
||||||
|
assert reloaded_rgba.load()[0, 0][3] == 0
|
||||||
|
|
|
@ -425,7 +425,13 @@ def _normalize_mode(im, initial_call=False):
|
||||||
palette_size = 256
|
palette_size = 256
|
||||||
if im.palette:
|
if im.palette:
|
||||||
palette_size = len(im.palette.getdata()[1]) // 3
|
palette_size = len(im.palette.getdata()[1]) // 3
|
||||||
return im.convert("P", palette=Image.ADAPTIVE, colors=palette_size)
|
im = im.convert("P", palette=Image.ADAPTIVE, colors=palette_size)
|
||||||
|
if im.palette.mode == "RGBA":
|
||||||
|
for rgba in im.palette.colors.keys():
|
||||||
|
if rgba[3] == 0:
|
||||||
|
im.info["transparency"] = im.palette.colors[rgba]
|
||||||
|
break
|
||||||
|
return im
|
||||||
else:
|
else:
|
||||||
return im.convert("P")
|
return im.convert("P")
|
||||||
return im.convert("L")
|
return im.convert("L")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user