From e77a7b6b4f0b496a70cabd8360f0988d32bea063 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 5 Aug 2022 23:29:58 +1000 Subject: [PATCH] Added support for RGBA PSD images --- Tests/images/rgba.psd | Bin 0 -> 2448 bytes Tests/test_file_psd.py | 7 ++++++- src/PIL/PsdImagePlugin.py | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 Tests/images/rgba.psd diff --git a/Tests/images/rgba.psd b/Tests/images/rgba.psd new file mode 100644 index 0000000000000000000000000000000000000000..45fb7c3cca0cbae6a57dc605931f9abcbba65013 GIT binary patch literal 2448 zcmcC;3J7LkWPkt`Ae92f91P4*F&PUdPhaM@V4eVwWCTM5{RSxZ) z8MZ0E)<#kC-9HyiiMjyLSY%W1C^>5gw1|Uw!%uTwF$)WhOkNXUK*X#b5%f{(auzz$&qhRY}%4S~TI0_+UbffV{|?*E2SL~IB!G|U}EqaiTVLf|38 P-Tx068b%~V>kJD3HVMyL literal 0 HcmV?d00001 diff --git a/Tests/test_file_psd.py b/Tests/test_file_psd.py index b4b5b7a0c65..4f934375c7c 100644 --- a/Tests/test_file_psd.py +++ b/Tests/test_file_psd.py @@ -4,7 +4,7 @@ from PIL import Image, PsdImagePlugin -from .helper import assert_image_similar, hopper, is_pypy +from .helper import assert_image_equal_tofile, assert_image_similar, hopper, is_pypy test_file = "Tests/images/hopper.psd" @@ -107,6 +107,11 @@ def test_open_after_exclusive_load(): im.load() +def test_rgba(): + with Image.open("Tests/images/rgba.psd") as im: + assert_image_equal_tofile(im, "Tests/images/imagedraw_square.png") + + def test_icc_profile(): with Image.open(test_file) as im: assert "icc_profile" in im.info diff --git a/src/PIL/PsdImagePlugin.py b/src/PIL/PsdImagePlugin.py index 04c2e4fe379..bd10e3b95dd 100644 --- a/src/PIL/PsdImagePlugin.py +++ b/src/PIL/PsdImagePlugin.py @@ -75,6 +75,9 @@ def _open(self): if channels > psd_channels: raise OSError("not enough channels") + if mode == "RGB" and psd_channels == 4: + mode = "RGBA" + channels = 4 self.mode = mode self._size = i32(s, 18), i32(s, 14)