From 3ccecd91cea6625612ef7e05d485058a7783bf07 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Sat, 3 Aug 2024 18:04:05 -0500 Subject: [PATCH] convert eps using pnmraw instead of ppmraw This lets Ghostscript choose the best device to use (pbmraw, pgmraw, ppmraw) based on the image data. --- Tests/test_file_eps.py | 2 +- src/PIL/EpsImagePlugin.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Tests/test_file_eps.py b/Tests/test_file_eps.py index f0f235f81..bca516a78 100644 --- a/Tests/test_file_eps.py +++ b/Tests/test_file_eps.py @@ -178,7 +178,7 @@ def test_load_long_binary_data(prefix: bytes) -> None: data = io.BytesIO(prefix + b"\n".join(simple_eps_file_with_long_binary_data)) with Image.open(data) as img: img.load() - assert img.mode == "RGB" + assert img.mode == "1" assert img.size == (100, 100) assert img.format == "EPS" diff --git a/src/PIL/EpsImagePlugin.py b/src/PIL/EpsImagePlugin.py index dd6ae4a77..f6c1ea2a5 100644 --- a/src/PIL/EpsImagePlugin.py +++ b/src/PIL/EpsImagePlugin.py @@ -121,7 +121,13 @@ def Ghostscript( lengthfile -= len(s) f.write(s) - device = "pngalpha" if transparency else "ppmraw" + if transparency: + # "RGBA" + device = "pngalpha" + else: + # "pnmraw" automatically chooses between + # PBM ("1"), PGM ("L"), and PPM ("RGB"). + device = "pnmraw" # Build Ghostscript command command = [