Create function process() that does the main work of main().
[toast/gimp_passport.git] / gimp_passport.py
index 1aafe73..4350108 100644 (file)
@@ -159,13 +159,12 @@ def downsample_large(img: Image, max_dpi: Optional[int]) -> Image:
     return img
 
 
-def main(paper_width_mm: float, paper_height_mm: float, paper_margin_mm: float,
+def process(paper_width_mm: float, paper_height_mm: float, paper_margin_mm: float,
          photo_width_mm: float, photo_height_mm: float, photo_spacing_mm: float,
          max_dpi: Optional[int],
          bbox: Tuple[int,int,int,int],
-         source_image: str, dest_image: str):
-    orig_photo = Image.open(source_image)
-    passport_tile = make_passport(orig_photo, bbox, 0.75, photo_width_mm, photo_height_mm)
+         source_image: Image) -> Image:
+    passport_tile = make_passport(source_image, bbox, 0.75, photo_width_mm, photo_height_mm)
     dpi = passport_tile.info['dpi'][0]
     paper = Image.new('RGB', (mm_to_pixel(paper_width_mm, dpi), mm_to_pixel(paper_height_mm, dpi)), 'white')
     paper.info['dpi'] = (dpi, dpi)
@@ -176,7 +175,18 @@ def main(paper_width_mm: float, paper_height_mm: float, paper_margin_mm: float,
     cut_lines_xy(paper, columns, rows, passport_tile.size, margin, spacing)
     halo(paper, columns, rows, passport_tile.size, 1, margin, spacing)
     tile(paper, passport_tile, columns, rows, margin, spacing)
-    paper = downsample_large(paper, max_dpi)
+    return downsample_large(paper, max_dpi)
+
+
+def main(paper_width_mm: float, paper_height_mm: float, paper_margin_mm: float,
+         photo_width_mm: float, photo_height_mm: float, photo_spacing_mm: float,
+         max_dpi: Optional[int],
+         bbox: Tuple[int,int,int,int],
+         source_image: str, dest_image: str):
+    orig_photo = Image.open(source_image)
+    paper = process(paper_width_mm, paper_height_mm, paper_margin_mm,
+            photo_width_mm, photo_height_mm, photo_spacing_mm,
+            max_dpi, bbox, orig_photo)
     paper.save(dest_image, dpi=paper.info['dpi'])