Support parameter --photo-spacing in main() and command line.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 5 Jun 2019 04:35:08 +0000 (06:35 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 5 Jun 2019 04:35:08 +0000 (06:35 +0200)
gimp_passport.py
test_gimp_passport.py

index 03a3318..481c26c 100644 (file)
@@ -77,10 +77,11 @@ def tile(img: Image, paper_width_mm: float, paper_height_mm: float, margin_mm: f
 
 
 def main(paper_width_mm: float, paper_height_mm: float, paper_margin_mm: float,
-         photo_width_mm: float, photo_height_mm: float, source_image: str, dest_image: str):
+         photo_width_mm: float, photo_height_mm: float, photo_spacing_mm: float,
+         source_image: str, dest_image: str):
     img = Image.open(source_image)
     photo = make_passport(img, 0.75, photo_width_mm, photo_height_mm)
-    paper = tile(photo, paper_width_mm, paper_height_mm, paper_margin_mm, 0.)
+    paper = tile(photo, paper_width_mm, paper_height_mm, paper_margin_mm, photo_spacing_mm)
     paper.save(dest_image, dpi=paper.info['dpi'])
 
 
@@ -92,7 +93,9 @@ if __name__ == '__main__':
     parser.add_argument('--paper-margin', type=float, default=4., help='paper margin in mm (default: 4)')
     parser.add_argument('--photo-width', type=float, default=35., help='passport photo width in mm (default: 35)')
     parser.add_argument('--photo-height', type=float, default=45., help='passport photo height in mm (default: 45)')
+    parser.add_argument('--photo-spacing', type=float, default=0., help='space between passport photos in mm (default: 0)')
     parser.add_argument('source', help='sourse image')
     parser.add_argument('dest', help='destination image')
     args = parser.parse_args()
-    main(args.paper_width, args.paper_height, args.paper_margin, args.photo_width, args.photo_height, args.source, args.dest)
+    main(args.paper_width, args.paper_height, args.paper_margin, args.photo_width, args.photo_height,
+         args.photo_spacing, args.source, args.dest)
index 946a94f..d77dad0 100644 (file)
@@ -26,7 +26,7 @@ class TestMakePassport(unittest.TestCase):
         img.info['dpi'] = (dpi, dpi)
         draw = ImageDraw.ImageDraw(img)
         draw.rectangle((0, 0, img.width, img.height-1), outline='black')
-        paper = tile(img, 150, 100, 4, 0.)
+        paper = tile(img, 150, 100, 4, 2.)
         self.assertIsInstance(paper, Image.Image)
 
     def test_main(self):
@@ -34,5 +34,5 @@ class TestMakePassport(unittest.TestCase):
         dest = 'test_image_result.png'
         if os.path.exists(dest):
             os.remove(dest)
-        main(35., 45., 4., 100., 150., source, dest)
+        main(35., 45., 4., 100., 150., 0., source, dest)
         self.assertTrue(os.path.exists(dest))