Removed DPI rounding from PNG loading

This commit is contained in:
Andrew Murray 2021-05-07 20:39:05 +10:00
parent 8354fa4929
commit 9d72542c08
2 changed files with 5 additions and 18 deletions

View File

@ -386,25 +386,12 @@ class TestFilePng:
# Check dpi roundtripping
with Image.open(TEST_PNG_FILE) as im:
im = roundtrip(im, dpi=(100, 100))
assert im.info["dpi"] == (100, 100)
im = roundtrip(im, dpi=(100.33, 100.33))
assert im.info["dpi"] == (100.33, 100.33)
def test_load_dpi_rounding(self):
# Round up
def test_load_float_dpi(self):
with Image.open(TEST_PNG_FILE) as im:
assert im.info["dpi"] == (96, 96)
# Round down
with Image.open("Tests/images/icc_profile_none.png") as im:
assert im.info["dpi"] == (72, 72)
def test_save_dpi_rounding(self):
with Image.open(TEST_PNG_FILE) as im:
im = roundtrip(im, dpi=(72.2, 72.2))
assert im.info["dpi"] == (72, 72)
im = roundtrip(im, dpi=(72.8, 72.8))
assert im.info["dpi"] == (73, 73)
assert im.info["dpi"] == (95.9866, 95.9866)
def test_roundtrip_text(self):
# Check text roundtripping

View File

@ -500,7 +500,7 @@ class PngStream(ChunkStream):
px, py = i32(s, 0), i32(s, 4)
unit = s[8]
if unit == 1: # meter
dpi = int(px * 0.0254 + 0.5), int(py * 0.0254 + 0.5)
dpi = px * 0.0254, py * 0.0254
self.im_info["dpi"] = dpi
elif unit == 0:
self.im_info["aspect"] = px, py