Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/PIL/MpoImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ def _save_all(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
+ b"MPF\0"
+ b" " * ifd_length
)
exif = im_frame.encoderinfo.get("exif")
if isinstance(exif, Image.Exif):
exif = exif.tobytes()
im_frame.encoderinfo["exif"] = exif
if exif:
if exif := im_frame.encoderinfo.get("exif"):
if isinstance(exif, Image.Exif):
exif = exif.tobytes()
im_frame.encoderinfo["exif"] = exif
mpf_offset += 4 + len(exif)

JpegImagePlugin._save(im_frame, fp, filename)
Expand Down
12 changes: 4 additions & 8 deletions src/PIL/PngImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1403,8 +1403,7 @@ def _save(

chunks = [b"cHRM", b"cICP", b"gAMA", b"sBIT", b"sRGB", b"tIME"]

icc = im.encoderinfo.get("icc_profile", im.info.get("icc_profile"))
if icc:
if icc := im.encoderinfo.get("icc_profile", im.info.get("icc_profile")):
# ICC profile
# according to PNG spec, the iCCP chunk contains:
# Profile name 1-79 bytes (character string)
Expand All @@ -1419,8 +1418,7 @@ def _save(
# Disallow sRGB chunks when an iCCP-chunk has been emitted.
chunks.remove(b"sRGB")

info = im.encoderinfo.get("pnginfo")
if info:
if info := im.encoderinfo.get("pnginfo"):
chunks_multiple_allowed = [b"sPLT", b"iTXt", b"tEXt", b"zTXt"]
for info_chunk in info.chunks:
cid, data = info_chunk[:2]
Expand Down Expand Up @@ -1472,8 +1470,7 @@ def _save(
alpha_bytes = colors
chunk(fp, b"tRNS", alpha[:alpha_bytes])

dpi = im.encoderinfo.get("dpi")
if dpi:
if dpi := im.encoderinfo.get("dpi"):
chunk(
fp,
b"pHYs",
Expand All @@ -1490,8 +1487,7 @@ def _save(
chunks.remove(cid)
chunk(fp, cid, data)

exif = im.encoderinfo.get("exif")
if exif:
if exif := im.encoderinfo.get("exif"):
if isinstance(exif, Image.Exif):
exif = exif.tobytes(8)
if exif.startswith(b"Exif\x00\x00"):
Expand Down
Loading