mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-11 08:42:35 +03:00
Use encoderinfo of first image as default for appended TIFF images
If no encoderinfo is specified on an appended TIFF image, use the encoder info from the first image. This restores 11.1.0 behavior, while allowing an image specific override.
This commit is contained in:
parent
3c71559804
commit
8eae4cf1b2
|
@ -696,15 +696,19 @@ class TestFileTiff:
|
|||
im = hopper()
|
||||
im2 = Image.new("L", (128, 128))
|
||||
im2.encoderinfo = {"tiffinfo": {278: 256}}
|
||||
im.save(outfile, save_all=True, append_images=[im2])
|
||||
im3 = Image.new("L", (128, 128))
|
||||
im.save(outfile, save_all=True, append_images=[im2, im3], tiffinfo={278: 512})
|
||||
|
||||
with Image.open(outfile) as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
assert im.tag_v2[278] == 128
|
||||
assert im.tag_v2[278] == 512
|
||||
|
||||
im.seek(1)
|
||||
assert im.tag_v2[278] == 256
|
||||
|
||||
im.seek(2)
|
||||
assert im.tag_v2[278] == 512
|
||||
|
||||
def test_strip_raw(self) -> None:
|
||||
infile = "Tests/images/tiff_strip_raw.tif"
|
||||
with Image.open(infile) as im:
|
||||
|
|
|
@ -2302,7 +2302,9 @@ class AppendingTiffWriter(io.BytesIO):
|
|||
|
||||
|
||||
def _save_all(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
||||
append_images = list(im.encoderinfo.get("append_images", []))
|
||||
encoderinfo = im.encoderinfo.copy()
|
||||
encoderconfig = im.encoderconfig
|
||||
append_images = list(encoderinfo.get("append_images", []))
|
||||
if not hasattr(im, "n_frames") and not append_images:
|
||||
return _save(im, fp, filename)
|
||||
|
||||
|
@ -2311,9 +2313,9 @@ def _save_all(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
|||
with AppendingTiffWriter(fp) as tf:
|
||||
for ims in [im] + append_images:
|
||||
if not hasattr(ims, "encoderinfo"):
|
||||
ims.encoderinfo = {}
|
||||
ims.encoderinfo = encoderinfo
|
||||
if not hasattr(ims, "encoderconfig"):
|
||||
ims.encoderconfig = ()
|
||||
ims.encoderconfig = encoderconfig
|
||||
nfr = getattr(ims, "n_frames", 1)
|
||||
|
||||
for idx in range(nfr):
|
||||
|
|
Loading…
Reference in New Issue
Block a user