Skip to content

Commit 14e924d

Browse files
committed
If append_images is populated, default save_all to True
1 parent d7d48df commit 14e924d

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

Tests/test_file_gif.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,12 @@ def test_append_images(tmp_path: Path) -> None:
11341134
ims = [Image.new("RGB", (100, 100), color) for color in ["#0f0", "#00f"]]
11351135
im.copy().save(out, save_all=True, append_images=ims)
11361136

1137+
with Image.open(out) as reread:
1138+
assert reread.n_frames == 3
1139+
1140+
# Test append_images without save_all
1141+
im.copy().save(out, append_images=ims)
1142+
11371143
with Image.open(out) as reread:
11381144
assert reread.n_frames == 3
11391145

docs/handbook/image-file-formats.rst

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,9 @@ following options are available::
229229
im.save(out, save_all=True, append_images=[im1, im2, ...])
230230

231231
**save_all**
232-
If present and true, all frames of the image will be saved. If
233-
not, then only the first frame of a multiframe image will be saved.
232+
If present and true, or if ``append_images`` is not empty, all frames of
233+
the image will be saved. Otherwise, only the first frame of a multiframe
234+
image will be saved.
234235

235236
**append_images**
236237
A list of images to append as additional frames. Each of the
@@ -716,8 +717,8 @@ Saving
716717

717718
When calling :py:meth:`~PIL.Image.Image.save` to write an MPO file, by default
718719
only the first frame of a multiframe image will be saved. If the ``save_all``
719-
argument is present and true, then all frames will be saved, and the following
720-
option will also be available.
720+
argument is present and true, or if ``append_images`` is not empty, all frames
721+
will be saved.
721722

722723
**append_images**
723724
A list of images to append as additional pictures. Each of the
@@ -927,7 +928,8 @@ Saving
927928

928929
When calling :py:meth:`~PIL.Image.Image.save`, by default only a single frame PNG file
929930
will be saved. To save an APNG file (including a single frame APNG), the ``save_all``
930-
parameter must be set to ``True``. The following parameters can also be set:
931+
parameter should be set to ``True`` or ``append_images`` should not be empty. The
932+
following parameters can also be set:
931933

932934
**default_image**
933935
Boolean value, specifying whether or not the base image is a default image.
@@ -1156,7 +1158,8 @@ Saving
11561158
The :py:meth:`~PIL.Image.Image.save` method can take the following keyword arguments:
11571159

11581160
**save_all**
1159-
If true, Pillow will save all frames of the image to a multiframe tiff document.
1161+
If true, or if ``append_images`` is not empty, Pillow will save all frames of the
1162+
image to a multiframe tiff document.
11601163

11611164
.. versionadded:: 3.4.0
11621165

@@ -1308,8 +1311,8 @@ Saving sequences
13081311

13091312
When calling :py:meth:`~PIL.Image.Image.save` to write a WebP file, by default
13101313
only the first frame of a multiframe image will be saved. If the ``save_all``
1311-
argument is present and true, then all frames will be saved, and the following
1312-
options will also be available.
1314+
argument is present and true, or if ``append_images`` is not empty, all frames
1315+
will be saved, and the following options will also be available.
13131316

13141317
**append_images**
13151318
A list of images to append as additional frames. Each of the
@@ -1611,15 +1614,14 @@ The :py:meth:`~PIL.Image.Image.save` method can take the following keyword argum
16111614
**save_all**
16121615
If a multiframe image is used, by default, only the first image will be saved.
16131616
To save all frames, each frame to a separate page of the PDF, the ``save_all``
1614-
parameter must be present and set to ``True``.
1617+
parameter should be present and set to ``True`` or ``append_images`` should not be
1618+
empty.
16151619

16161620
.. versionadded:: 3.0.0
16171621

16181622
**append_images**
16191623
A list of :py:class:`PIL.Image.Image` objects to append as additional pages. Each
1620-
of the images in the list can be single or multiframe images. The ``save_all``
1621-
parameter must be present and set to ``True`` in conjunction with
1622-
``append_images``.
1624+
of the images in the list can be single or multiframe images.
16231625

16241626
.. versionadded:: 4.2.0
16251627

docs/handbook/tutorial.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,6 @@ You can create animated GIFs with Pillow, e.g.
534534
# Save the images as an animated GIF
535535
images[0].save(
536536
"animated_hopper.gif",
537-
save_all=True,
538537
append_images=images[1:],
539538
duration=500, # duration of each frame in milliseconds
540539
loop=0, # loop forever

src/PIL/Image.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,7 +2500,7 @@ def save(
25002500
# may mutate self!
25012501
self._ensure_mutable()
25022502

2503-
save_all = params.pop("save_all", False)
2503+
save_all = params.pop("save_all", None)
25042504
self.encoderinfo = {**getattr(self, "encoderinfo", {}), **params}
25052505
self.encoderconfig: tuple[Any, ...] = ()
25062506

@@ -2520,7 +2520,11 @@ def save(
25202520

25212521
if format.upper() not in SAVE:
25222522
init()
2523-
if save_all:
2523+
if save_all or (
2524+
save_all is None
2525+
and params.get("append_images")
2526+
and format.upper() in SAVE_ALL
2527+
):
25242528
save_handler = SAVE_ALL[format.upper()]
25252529
else:
25262530
save_handler = SAVE[format.upper()]

0 commit comments

Comments
 (0)