Return the dpi value calculated for `resolution_tag`, which can be either TIFF_TAG.X_RESOLUTION or TIFF_TAG.Y_RESOLUTION. The calculation is based on the values of both that tag and the TIFF_TAG.RESOLUTION_UNIT tag in this parser's |_IfdEntries| instance.
(self, resolution_tag)
| 86 | return BIG_ENDIAN if endian_str == b"MM" else LITTLE_ENDIAN |
| 87 | |
| 88 | def _dpi(self, resolution_tag): |
| 89 | """Return the dpi value calculated for `resolution_tag`, which can be either |
| 90 | TIFF_TAG.X_RESOLUTION or TIFF_TAG.Y_RESOLUTION. |
| 91 | |
| 92 | The calculation is based on the values of both that tag and the |
| 93 | TIFF_TAG.RESOLUTION_UNIT tag in this parser's |_IfdEntries| instance. |
| 94 | """ |
| 95 | ifd_entries = self._ifd_entries |
| 96 | |
| 97 | if resolution_tag not in ifd_entries: |
| 98 | return 72 |
| 99 | |
| 100 | # resolution unit defaults to inches (2) |
| 101 | resolution_unit = ifd_entries.get(TIFF_TAG.RESOLUTION_UNIT, 2) |
| 102 | |
| 103 | if resolution_unit == 1: # aspect ratio only |
| 104 | return 72 |
| 105 | # resolution_unit == 2 for inches, 3 for centimeters |
| 106 | units_per_inch = 1 if resolution_unit == 2 else 2.54 |
| 107 | dots_per_unit = ifd_entries[resolution_tag] |
| 108 | return int(round(dots_per_unit * units_per_inch)) |
| 109 | |
| 110 | @classmethod |
| 111 | def _make_stream_reader(cls, stream): |