Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed WMF DPI rounding #5470

Merged
merged 1 commit into from May 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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