From 8e730e17ae5608616e57194a25629c48ad033cfa Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 13 Jul 2024 13:00:58 +1000 Subject: [PATCH] Allow saving I;16 images as PPM --- Tests/test_file_ppm.py | 2 ++ src/PIL/PpmImagePlugin.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Tests/test_file_ppm.py b/Tests/test_file_ppm.py index d6451ec18..fa5027448 100644 --- a/Tests/test_file_ppm.py +++ b/Tests/test_file_ppm.py @@ -95,7 +95,9 @@ def test_16bit_pgm_write(tmp_path: Path) -> None: with Image.open("Tests/images/16_bit_binary.pgm") as im: filename = str(tmp_path / "temp.pgm") im.save(filename, "PPM") + assert_image_equal_tofile(im, filename) + im.convert("I;16").save(filename, "PPM") assert_image_equal_tofile(im, filename) diff --git a/src/PIL/PpmImagePlugin.py b/src/PIL/PpmImagePlugin.py index 16c9ccbba..211577e16 100644 --- a/src/PIL/PpmImagePlugin.py +++ b/src/PIL/PpmImagePlugin.py @@ -333,7 +333,7 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: rawmode, head = "1;I", b"P4" elif im.mode == "L": rawmode, head = "L", b"P5" - elif im.mode == "I": + elif im.mode in ("I", "I;16"): rawmode, head = "I;16B", b"P5" elif im.mode in ("RGB", "RGBA"): rawmode, head = "RGB", b"P6"