Skip to content

Commit

Permalink
Merge pull request #5470 from radarhere/wmf_dpi_rounding
Browse files Browse the repository at this point in the history
Removed WMF DPI rounding
  • Loading branch information
hugovk committed May 16, 2021
2 parents 3f01813 + b9c571a commit d53a664
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
Binary file removed Tests/images/drawing_roundDown.emf
Binary file not shown.
9 changes: 2 additions & 7 deletions Tests/test_file_wmf.py
Expand Up @@ -44,14 +44,9 @@ def save(self, im, fp, filename):
WmfImagePlugin.register_handler(original_handler)


def test_load_dpi_rounding():
# Round up
def test_load_float_dpi():
with Image.open("Tests/images/drawing.emf") as im:
assert im.info["dpi"] == 1424

# Round down
with Image.open("Tests/images/drawing_roundDown.emf") as im:
assert im.info["dpi"] == 1426
assert im.info["dpi"] == 1423.7668161434979


def test_load_set_dpi():
Expand Down
6 changes: 3 additions & 3 deletions src/PIL/WmfImagePlugin.py
Expand Up @@ -127,8 +127,8 @@ def _open(self):
size = x1 - x0, y1 - y0

# calculate dots per inch from bbox and frame
xdpi = int(2540.0 * (x1 - y0) / (frame[2] - frame[0]) + 0.5)
ydpi = int(2540.0 * (y1 - y0) / (frame[3] - frame[1]) + 0.5)
xdpi = 2540.0 * (x1 - y0) / (frame[2] - frame[0])
ydpi = 2540.0 * (y1 - y0) / (frame[3] - frame[1])

self.info["wmf_bbox"] = x0, y0, x1, y1

Expand All @@ -152,7 +152,7 @@ def _load(self):

def load(self, dpi=None):
if dpi is not None and self._inch is not None:
self.info["dpi"] = int(dpi + 0.5)
self.info["dpi"] = dpi
x0, y0, x1, y1 = self.info["wmf_bbox"]
self._size = (
(x1 - x0) * self.info["dpi"] // self._inch,
Expand Down

0 comments on commit d53a664

Please sign in to comment.