Merge pull request #5470 from radarhere/wmf_dpi_rounding

Removed WMF DPI rounding
This commit is contained in:
Hugo van Kemenade 2021-05-16 19:57:14 +03:00 committed by GitHub
commit d53a664866
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 10 deletions

Binary file not shown.

View File

@ -44,14 +44,9 @@ def test_register_handler(tmp_path):
WmfImagePlugin.register_handler(original_handler) WmfImagePlugin.register_handler(original_handler)
def test_load_dpi_rounding(): def test_load_float_dpi():
# Round up
with Image.open("Tests/images/drawing.emf") as im: with Image.open("Tests/images/drawing.emf") as im:
assert im.info["dpi"] == 1424 assert im.info["dpi"] == 1423.7668161434979
# Round down
with Image.open("Tests/images/drawing_roundDown.emf") as im:
assert im.info["dpi"] == 1426
def test_load_set_dpi(): def test_load_set_dpi():

View File

@ -127,8 +127,8 @@ class WmfStubImageFile(ImageFile.StubImageFile):
size = x1 - x0, y1 - y0 size = x1 - x0, y1 - y0
# calculate dots per inch from bbox and frame # calculate dots per inch from bbox and frame
xdpi = int(2540.0 * (x1 - y0) / (frame[2] - frame[0]) + 0.5) xdpi = 2540.0 * (x1 - y0) / (frame[2] - frame[0])
ydpi = int(2540.0 * (y1 - y0) / (frame[3] - frame[1]) + 0.5) ydpi = 2540.0 * (y1 - y0) / (frame[3] - frame[1])
self.info["wmf_bbox"] = x0, y0, x1, y1 self.info["wmf_bbox"] = x0, y0, x1, y1
@ -152,7 +152,7 @@ class WmfStubImageFile(ImageFile.StubImageFile):
def load(self, dpi=None): def load(self, dpi=None):
if dpi is not None and self._inch is not 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"] x0, y0, x1, y1 = self.info["wmf_bbox"]
self._size = ( self._size = (
(x1 - x0) * self.info["dpi"] // self._inch, (x1 - x0) * self.info["dpi"] // self._inch,