From b45fdd081722f8cb9f53563399ddde108c2d0c5f Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 10 Jul 2021 15:15:10 +1000 Subject: [PATCH] Allow saving WebP with icc_profile None --- Tests/test_file_webp.py | 7 +++++++ src/PIL/WebPImagePlugin.py | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Tests/test_file_webp.py b/Tests/test_file_webp.py index 7fdb32ef4..420594b0c 100644 --- a/Tests/test_file_webp.py +++ b/Tests/test_file_webp.py @@ -104,6 +104,13 @@ class TestFileWebp: hopper().save(buffer_method, format="WEBP", method=6) assert buffer_no_args.getbuffer() != buffer_method.getbuffer() + def test_icc_profile(self, tmp_path): + self._roundtrip(tmp_path, self.rgb_mode, 12.5, {"icc_profile": None}) + if _webp.HAVE_WEBPANIM: + self._roundtrip( + tmp_path, self.rgb_mode, 12.5, {"icc_profile": None, "save_all": True} + ) + def test_write_unsupported_mode_L(self, tmp_path): """ Saving a black-and-white file to WebP format should work, and be diff --git a/src/PIL/WebPImagePlugin.py b/src/PIL/WebPImagePlugin.py index b63a07ca8..590161f3e 100644 --- a/src/PIL/WebPImagePlugin.py +++ b/src/PIL/WebPImagePlugin.py @@ -202,7 +202,7 @@ def _save_all(im, fp, filename): lossless = im.encoderinfo.get("lossless", False) quality = im.encoderinfo.get("quality", 80) method = im.encoderinfo.get("method", 0) - icc_profile = im.encoderinfo.get("icc_profile", "") + icc_profile = im.encoderinfo.get("icc_profile") or "" exif = im.encoderinfo.get("exif", "") if isinstance(exif, Image.Exif): exif = exif.tobytes() @@ -309,7 +309,7 @@ def _save_all(im, fp, filename): def _save(im, fp, filename): lossless = im.encoderinfo.get("lossless", False) quality = im.encoderinfo.get("quality", 80) - icc_profile = im.encoderinfo.get("icc_profile", "") + icc_profile = im.encoderinfo.get("icc_profile") or "" exif = im.encoderinfo.get("exif", "") if isinstance(exif, Image.Exif): exif = exif.tobytes()