Error is shown if nothing is selected.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Thu, 20 Jun 2019 21:43:17 +0000 (23:43 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Thu, 20 Jun 2019 21:43:17 +0000 (23:43 +0200)
gimp_passport_plugin.py

index 26abbb4..486ed28 100755 (executable)
@@ -14,14 +14,16 @@ def create_passport(image, drawable, paper_height_mm, paper_width_mm):
     pil_img = PIL.Image.frombytes('RGB', (drawable.width, drawable.height), rgn[:, :])
 
     # get face extent
-    # non_empty, x1, y1, x2, y2 = pdb.gimp_selection_bounds(image)
+    non_empty, left, top, right, bottom = pdb.gimp_selection_bounds(image)
+    if not non_empty:
+        raise RuntimeError('Please select the face first.')
 
     # pdb.gimp_image_find_next_guide(image, 0)
     # pdb.gimp_image_get_guide_orientation(image, 6)
     # pdb.gimp_image_get_guide_position(image, 6)
 
     # perform processing
-    pil_img = pil_img.transpose(PIL.Image.ROTATE_180)
+    pil_img = pil_img.crop((left, top, right, bottom))
 
     # 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))