MCPcopy Index your code
hub / github.com/python-openxml/python-docx / from_stream

Method from_stream

src/docx/image/jpeg.py:345–360  ·  view source on GitHub ↗

Extract the horizontal and vertical dots-per-inch value from the APP1 header at `offset` in `stream`.

(cls, stream, marker_code, offset)

Source from the content-addressed store, hash-verified

343
344 @classmethod
345 def from_stream(cls, stream, marker_code, offset):
346 """Extract the horizontal and vertical dots-per-inch value from the APP1 header
347 at `offset` in `stream`."""
348 # field off len type notes
349 # -------------------- --- --- ----- ----------------------------
350 # segment length 0 2 short
351 # Exif identifier 2 6 6 chr 'Exif\x00\x00'
352 # TIFF byte order 8 2 2 chr 'II'=little 'MM'=big endian
353 # meaning of universe 10 2 2 chr '*\x00' or '\x00*' depending
354 # IFD0 off fr/II or MM 10 16 long relative to ...?
355 # -------------------- --- --- ----- ----------------------------
356 segment_length = stream.read_short(offset)
357 if cls._is_non_Exif_APP1_segment(stream, offset):
358 return cls(marker_code, offset, segment_length, 72, 72)
359 tiff = cls._tiff_from_exif_segment(stream, offset, segment_length)
360 return cls(marker_code, offset, segment_length, tiff.horz_dpi, tiff.vert_dpi)
361
362 @property
363 def horz_dpi(self):

Callers

nothing calls this directly

Calls 3

read_shortMethod · 0.80

Tested by

no test coverage detected