Allow alpha differences to indicate different frames when saving GIF

This commit is contained in:
Andrew Murray 2023-06-14 14:21:07 +10:00
parent 119a0dfb01
commit 541d2605b9
3 changed files with 15 additions and 3 deletions

View File

@ -1130,6 +1130,18 @@ def test_bbox(tmp_path):
assert reread.n_frames == 2
def test_bbox_alpha(tmp_path):
out = str(tmp_path / "temp.gif")
im = Image.new("RGBA", (1, 2), (255, 0, 0, 255))
im.putpixel((0, 1), (255, 0, 0, 0))
im2 = Image.new("RGBA", (1, 2), (255, 0, 0, 0))
im.save(out, save_all=True, append_images=[im2])
with Image.open(out) as reread:
assert reread.n_frames == 2
def test_palette_save_L(tmp_path):
# Generate an L mode image with a separate palette

View File

@ -569,9 +569,9 @@ def _getbbox(base_im, im_frame):
delta = ImageChops.subtract_modulo(im_frame, base_im)
else:
delta = ImageChops.subtract_modulo(
im_frame.convert("RGB"), base_im.convert("RGB")
im_frame.convert("RGBA"), base_im.convert("RGBA")
)
return delta.getbbox()
return delta.getbbox(alpha_only=False)
def _write_multiple_frames(im, fp, palette):

View File

@ -1140,7 +1140,7 @@ def _write_multiple_frames(im, fp, chunk, rawmode, default_image, append_images)
delta = ImageChops.subtract_modulo(
im_frame.convert("RGBA"), base_im.convert("RGBA")
)
bbox = delta.im.getbbox(False)
bbox = delta.getbbox(alpha_only=False)
if (
not bbox
and prev_disposal == encoderinfo.get("disposal")