make_passport() now takes an Image instance instead of a filename.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Mon, 3 Jun 2019 21:12:26 +0000 (23:12 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Mon, 3 Jun 2019 21:12:26 +0000 (23:12 +0200)
gimp_passport.py

index da046ee..af6e54c 100644 (file)
@@ -1,12 +1,11 @@
 import argparse
 from PIL import Image
 
-def make_passport(image_filename: str, fpr: float, width_mm: float, height_mm: float) -> Image:
+
+def make_passport(img_rgba: Image, fpr: float, width_mm: float, height_mm: float) -> Image:
     """
     :param fpr: face to picture ratio, e.g. 2/3
     """
-    img_rgba = Image.open(image_filename)
-
     # get bounding box of head
     bands = img_rgba.getbands()
     if 'A' not in bands:
@@ -14,7 +13,6 @@ def make_passport(image_filename: str, fpr: float, width_mm: float, height_mm: f
     alpha = img_rgba.getdata(bands.index('A'))
     bbox_head = alpha.getbbox()  # bounding box of head
 
-
     # get bounding box of passport image ("pic")
     left, top, right, bottom = bbox_head
     height = bottom - top
@@ -34,7 +32,8 @@ def make_passport(image_filename: str, fpr: float, width_mm: float, height_mm: f
 
 
 def main(source_image: str, dest_image: str):
-    pic = make_passport(source_image, 0.75, 35., 45.)
+    img = Image.open(source_image)
+    pic = make_passport(img, 0.75, 35., 45.)
     pic.save(dest_image)