Now gimp_passport is used by gimp_passport_plugin.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Tue, 25 Jun 2019 21:56:36 +0000 (23:56 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Tue, 25 Jun 2019 21:56:36 +0000 (23:56 +0200)
gimp_passport_plugin.py

index d7ecf11..5564518 100755 (executable)
@@ -2,6 +2,7 @@
 
 from gimpfu import *
 import PIL.Image
+import gimp_passport
 
 
 def create_passport(image, drawable, paper_height_mm, paper_width_mm):
@@ -15,23 +16,31 @@ def create_passport(image, drawable, paper_height_mm, paper_width_mm):
         pdb.gimp_message('Please select the face first.')
         return image
 
-    # convert GIMP image to PIL image:
-    rgn = drawable.get_pixel_rgn(0, 0, drawable.width, drawable.height)
-    pil_img = PIL.Image.frombytes('RGB', (drawable.width, drawable.height), rgn[:, :])
-
     # pdb.gimp_image_find_next_guide(image, 0)
     # pdb.gimp_image_get_guide_orientation(image, 6)
     # pdb.gimp_image_get_guide_position(image, 6)
 
+    photo_width_mm = 35.
+    photo_height_mm = 45.
+    fpr = 0.75
+    margin_mm = 4.
+    spacing_mm = 1.
+
+    # convert GIMP image to PIL image:
+    rgn = drawable.get_pixel_rgn(0, 0, drawable.width, drawable.height)
+    pil_img = PIL.Image.frombytes('RGB', (drawable.width, drawable.height), rgn[:, :])
+
     # perform processing
-    pil_img = pil_img.crop((left, top, right, bottom))
+    # pil_paper = pil_img.crop((left, top, right, bottom))
+    pil_photo = gimp_passport.make_passport(pil_img, (left, top, right, bottom), fpr, photo_width_mm, photo_height_mm)
+    pil_paper = gimp_passport.tile(pil_photo, paper_width_mm, paper_height_mm, margin_mm, spacing_mm)
 
     # copy processed PIL to new GIMP image
-    image_new = pdb.gimp_image_new(pil_img.width, pil_img.height, pdb.gimp_image_base_type(image))
-    layer = gimp.Layer(image_new, "passport", image_new.width, image_new.height, pdb.gimp_image_base_type(image), 100, NORMAL_MODE)
+    image_new = pdb.gimp_image_new(pil_paper.width, pil_paper.height, pdb.gimp_image_base_type(image))
+    layer = gimp.Layer(image_new, "passport", pil_paper.width, pil_paper.height, pdb.gimp_image_base_type(image), 100, NORMAL_MODE)
     image_new.add_layer(layer)
     rgn = layer.get_pixel_rgn(0, 0, layer.width, layer.height, True)
-    rgn[:, :] = pil_img.tobytes()
+    rgn[:, :] = pil_paper.tobytes()
     gimp.Display(image_new)
     return image_new