Skip to content

Commit eb125c8

Browse files
author
Steve Canny
committed
img: add _SofMarker.px_width and .px_height
1 parent e080a7d commit eb125c8

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

docx/image/jpeg.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,17 @@ def from_stream(cls, stream, marker_code, offset):
333333
px_height = stream.read_short(offset, 3)
334334
px_width = stream.read_short(offset, 5)
335335
return cls(marker_code, offset, segment_length, px_width, px_height)
336+
337+
@property
338+
def px_height(self):
339+
"""
340+
Image height in pixels
341+
"""
342+
return self._px_height
343+
344+
@property
345+
def px_width(self):
346+
"""
347+
Image width in pixels
348+
"""
349+
return self._px_width

tests/image/test_jpeg.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,11 @@ def it_can_construct_from_a_stream_and_offset(self, from_stream_fixture):
260260
)
261261
assert isinstance(sof_marker, _SofMarker)
262262

263+
def it_knows_the_image_width_and_height(self):
264+
sof = _SofMarker(None, None, None, 42, 24)
265+
assert sof.px_width == 42
266+
assert sof.px_height == 24
267+
263268
# fixtures -------------------------------------------------------
264269

265270
@pytest.fixture

0 commit comments

Comments
 (0)