Skip to content

Commit 10ccbd7

Browse files
authored
If append_images is populated, default save_all to True (#8781)
Co-authored-by: Andrew Murray <[email protected]>
1 parent 095f599 commit 10ccbd7

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
@@ -1138,6 +1138,12 @@ def test_append_images(tmp_path: Path) -> None:
11381138
ims = [Image.new("RGB", (100, 100), color) for color in ["#0f0", "#00f"]]
11391139
im.copy().save(out, save_all=True, append_images=ims)
11401140

1141+
with Image.open(out) as reread:
1142+
assert reread.n_frames == 3
1143+
1144+
# Test append_images without save_all
1145+
im.copy().save(out, append_images=ims)
1146+
11411147
with Image.open(out) as reread:
11421148
assert reread.n_frames == 3
11431149

docs/handbook/image-file-formats.rst

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

237237
**save_all**
238-
If present and true, all frames of the image will be saved. If
239-
not, then only the first frame of a multiframe image will be saved.
238+
If present and true, or if ``append_images`` is not empty, all frames of
239+
the image will be saved. Otherwise, only the first frame of a multiframe
240+
image will be saved.
240241

241242
**append_images**
242243
A list of images to append as additional frames. Each of the
@@ -723,8 +724,8 @@ Saving
723724

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

729730
**append_images**
730731
A list of images to append as additional pictures. Each of the
@@ -934,7 +935,8 @@ Saving
934935

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

939941
**default_image**
940942
Boolean value, specifying whether or not the base image is a default image.
@@ -1163,7 +1165,8 @@ Saving
11631165
The :py:meth:`~PIL.Image.Image.save` method can take the following keyword arguments:
11641166

11651167
**save_all**
1166-
If true, Pillow will save all frames of the image to a multiframe tiff document.
1168+
If true, or if ``append_images`` is not empty, Pillow will save all frames of the
1169+
image to a multiframe tiff document.
11671170

11681171
.. versionadded:: 3.4.0
11691172

@@ -1313,8 +1316,8 @@ Saving sequences
13131316

13141317
When calling :py:meth:`~PIL.Image.Image.save` to write a WebP file, by default
13151318
only the first frame of a multiframe image will be saved. If the ``save_all``
1316-
argument is present and true, then all frames will be saved, and the following
1317-
options will also be available.
1319+
argument is present and true, or if ``append_images`` is not empty, all frames
1320+
will be saved, and the following options will also be available.
13181321

13191322
**append_images**
13201323
A list of images to append as additional frames. Each of the
@@ -1616,15 +1619,14 @@ The :py:meth:`~PIL.Image.Image.save` method can take the following keyword argum
16161619
**save_all**
16171620
If a multiframe image is used, by default, only the first image will be saved.
16181621
To save all frames, each frame to a separate page of the PDF, the ``save_all``
1619-
parameter must be present and set to ``True``.
1622+
parameter should be present and set to ``True`` or ``append_images`` should not be
1623+
empty.
16201624

16211625
.. versionadded:: 3.0.0
16221626

16231627
**append_images**
16241628
A list of :py:class:`PIL.Image.Image` objects to append as additional pages. Each
1625-
of the images in the list can be single or multiframe images. The ``save_all``
1626-
parameter must be present and set to ``True`` in conjunction with
1627-
``append_images``.
1629+
of the images in the list can be single or multiframe images.
16281630

16291631
.. versionadded:: 4.2.0
16301632

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
@@ -2527,13 +2527,17 @@ def save(
25272527
# may mutate self!
25282528
self._ensure_mutable()
25292529

2530-
save_all = params.pop("save_all", False)
2530+
save_all = params.pop("save_all", None)
25312531
self.encoderinfo = {**getattr(self, "encoderinfo", {}), **params}
25322532
self.encoderconfig: tuple[Any, ...] = ()
25332533

25342534
if format.upper() not in SAVE:
25352535
init()
2536-
if save_all:
2536+
if save_all or (
2537+
save_all is None
2538+
and params.get("append_images")
2539+
and format.upper() in SAVE_ALL
2540+
):
25372541
save_handler = SAVE_ALL[format.upper()]
25382542
else:
25392543
save_handler = SAVE[format.upper()]

0 commit comments

Comments
 (0)