diff --git a/Tests/images/drawing_roundDown.emf b/Tests/images/drawing_roundDown.emf deleted file mode 100644 index 6c3e20248..000000000 Binary files a/Tests/images/drawing_roundDown.emf and /dev/null differ diff --git a/Tests/test_file_wmf.py b/Tests/test_file_wmf.py index bf9d105e5..3f8bc96cc 100644 --- a/Tests/test_file_wmf.py +++ b/Tests/test_file_wmf.py @@ -44,14 +44,9 @@ def test_register_handler(tmp_path): 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(): diff --git a/src/PIL/WmfImagePlugin.py b/src/PIL/WmfImagePlugin.py index 87847a107..27f5d2f87 100644 --- a/src/PIL/WmfImagePlugin.py +++ b/src/PIL/WmfImagePlugin.py @@ -127,8 +127,8 @@ class WmfStubImageFile(ImageFile.StubImageFile): 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 @@ -152,7 +152,7 @@ class WmfStubImageFile(ImageFile.StubImageFile): 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,