Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c2907dc

Browse files
committed
Layer co-ordinates may be negative
1 parent df99d48 commit c2907dc

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed
8.03 KB
Binary file not shown.

Tests/test_file_psd.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ def test_rgba():
112112
assert_image_equal_tofile(im, "Tests/images/imagedraw_square.png")
113113

114114

115+
def test_negative_top_left_layer() -> None:
116+
with Image.open("Tests/images/negative_top_left_layer.psd") as im:
117+
assert im.layers[0][2] == (-50, -50, 50, 50)
118+
119+
115120
def test_layer_skip():
116121
with Image.open("Tests/images/five_channels.psd") as im:
117122
assert im.n_frames == 1

src/PIL/PsdImagePlugin.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from ._binary import i16be as i16
2525
from ._binary import i32be as i32
2626
from ._binary import si16be as si16
27+
from ._binary import si32be as si32
2728

2829
MODES = {
2930
# (photoshop mode, bits) -> (pil mode, required channels)
@@ -177,10 +178,10 @@ def read(size):
177178

178179
for _ in range(abs(ct)):
179180
# bounding box
180-
y0 = i32(read(4))
181-
x0 = i32(read(4))
182-
y1 = i32(read(4))
183-
x1 = i32(read(4))
181+
y0 = si32(read(4))
182+
x0 = si32(read(4))
183+
y1 = si32(read(4))
184+
x1 = si32(read(4))
184185

185186
# image info
186187
mode = []

src/PIL/_binary.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ def si32le(c: bytes, o: int = 0) -> int:
7777
return unpack_from("<i", c, o)[0]
7878

7979

80+
def si32be(c: bytes, o: int = 0) -> int:
81+
"""
82+
Converts a 4-bytes (32 bits) string to a signed integer, big endian.
83+
84+
:param c: string containing bytes to convert
85+
:param o: offset of bytes to convert in string
86+
"""
87+
return unpack_from(">i", c, o)[0]
88+
89+
8090
def i16be(c: bytes, o: int = 0) -> int:
8191
return unpack_from(">H", c, o)[0]
8292

0 commit comments

Comments
 (0)