Skip to content

Commit 736bb51

Browse files
author
Steve Canny
committed
img: add _App1Marker.horz_dpi and .vert_dpi
1 parent 35cb783 commit 736bb51

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

docx/image/jpeg.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,11 @@ class _App1Marker(_Marker):
399399
"""
400400
Represents a JFIF APP1 (Exif) marker segment.
401401
"""
402+
def __init__(self, marker_code, offset, length, horz_dpi, vert_dpi):
403+
super(_App1Marker, self).__init__(marker_code, offset, length)
404+
self._horz_dpi = horz_dpi
405+
self._vert_dpi = vert_dpi
406+
402407
@classmethod
403408
def from_stream(cls, stream, marker_code, offset):
404409
"""
@@ -421,6 +426,22 @@ def from_stream(cls, stream, marker_code, offset):
421426
marker_code, offset, segment_length, tiff.horz_dpi, tiff.vert_dpi
422427
)
423428

429+
@property
430+
def horz_dpi(self):
431+
"""
432+
Horizontal dots per inch specified in this marker, defaults to 72 if
433+
not specified.
434+
"""
435+
return self._horz_dpi
436+
437+
@property
438+
def vert_dpi(self):
439+
"""
440+
Vertical dots per inch specified in this marker, defaults to 72 if
441+
not specified.
442+
"""
443+
return self._vert_dpi
444+
424445
@classmethod
425446
def _is_non_Exif_APP1_segment(cls, stream, offset):
426447
"""

tests/image/test_jpeg.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,12 @@ def it_gets_a_tiff_from_its_Exif_segment_to_help_construct(
383383
Tiff_.from_stream.assert_called_once_with(substream_, None, None)
384384
assert tiff is tiff_
385385

386+
def it_knows_the_image_dpi(self):
387+
horz_dpi, vert_dpi = 42, 24
388+
app1 = _App1Marker(None, None, None, horz_dpi, vert_dpi)
389+
assert app1.horz_dpi == horz_dpi
390+
assert app1.vert_dpi == vert_dpi
391+
386392
# fixtures -------------------------------------------------------
387393

388394
@pytest.fixture

0 commit comments

Comments
 (0)