mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-05-29 10:13:09 +03:00
Consider transparency from each frame when saving
This commit is contained in:
parent
a575ec33d2
commit
6b2da2f123
|
@ -619,7 +619,7 @@ def test_dispose2_background(tmp_path):
|
||||||
assert im.getpixel((0, 0)) == (255, 0, 0)
|
assert im.getpixel((0, 0)) == (255, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
def test_transparency_in_second_frame():
|
def test_transparency_in_second_frame(tmp_path):
|
||||||
with Image.open("Tests/images/different_transparency.gif") as im:
|
with Image.open("Tests/images/different_transparency.gif") as im:
|
||||||
assert im.info["transparency"] == 0
|
assert im.info["transparency"] == 0
|
||||||
|
|
||||||
|
@ -629,6 +629,15 @@ def test_transparency_in_second_frame():
|
||||||
|
|
||||||
assert_image_equal_tofile(im, "Tests/images/different_transparency_merged.png")
|
assert_image_equal_tofile(im, "Tests/images/different_transparency_merged.png")
|
||||||
|
|
||||||
|
out = str(tmp_path / "temp.gif")
|
||||||
|
im.save(out, save_all=True)
|
||||||
|
|
||||||
|
with Image.open(out) as reread:
|
||||||
|
reread.seek(reread.tell() + 1)
|
||||||
|
assert_image_equal_tofile(
|
||||||
|
reread, "Tests/images/different_transparency_merged.png"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_no_transparency_in_second_frame():
|
def test_no_transparency_in_second_frame():
|
||||||
with Image.open("Tests/images/iss634.gif") as img:
|
with Image.open("Tests/images/iss634.gif") as img:
|
||||||
|
|
|
@ -573,10 +573,14 @@ def _write_multiple_frames(im, fp, palette):
|
||||||
im_frame = _normalize_mode(im_frame.copy())
|
im_frame = _normalize_mode(im_frame.copy())
|
||||||
if frame_count == 0:
|
if frame_count == 0:
|
||||||
for k, v in im_frame.info.items():
|
for k, v in im_frame.info.items():
|
||||||
|
if k == "transparency":
|
||||||
|
continue
|
||||||
im.encoderinfo.setdefault(k, v)
|
im.encoderinfo.setdefault(k, v)
|
||||||
im_frame = _normalize_palette(im_frame, palette, im.encoderinfo)
|
|
||||||
|
|
||||||
encoderinfo = im.encoderinfo.copy()
|
encoderinfo = im.encoderinfo.copy()
|
||||||
|
if "transparency" in im_frame.info:
|
||||||
|
encoderinfo.setdefault("transparency", im_frame.info["transparency"])
|
||||||
|
im_frame = _normalize_palette(im_frame, palette, encoderinfo)
|
||||||
if isinstance(duration, (list, tuple)):
|
if isinstance(duration, (list, tuple)):
|
||||||
encoderinfo["duration"] = duration[frame_count]
|
encoderinfo["duration"] = duration[frame_count]
|
||||||
if isinstance(disposal, (list, tuple)):
|
if isinstance(disposal, (list, tuple)):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user