After downsampling the image, the DPI value is now updated as well.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Thu, 27 Jun 2019 21:40:37 +0000 (23:40 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Thu, 27 Jun 2019 21:40:37 +0000 (23:40 +0200)
gimp_passport.py
test_gimp_passport.py

index cb905df..ba71585 100644 (file)
@@ -156,7 +156,9 @@ def downsample_large(img: Image, max_dpi: Optional[int]) -> Image:
     width, height = img.size
     width = int(round(width * max_dpi / dpi))
     height = int(round(height * max_dpi / dpi))
-    return img.resize((width, height))
+    img = img.resize((width, height))
+    img.info['dpi'] = (max_dpi, max_dpi)
+    return img
 
 
 def main(paper_width_mm: float, paper_height_mm: float, paper_margin_mm: float,
index 7d727f2..505b1ef 100644 (file)
@@ -64,6 +64,7 @@ class TestMakePassport(unittest.TestCase):
         dest = downsample_large(source, 45)
         self.assertEqual(int(round(source.width / 2)), dest.width)
         self.assertEqual(int(round(source.height / 2)), dest.height)
+        self.assertEqual((45, 45), dest.info['dpi'])
 
     def test_main(self):
         source = 'test_image.jpg'