Check first whether a selection exists before doing anything else (thanks Gregor).
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Tue, 25 Jun 2019 21:04:50 +0000 (23:04 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Tue, 25 Jun 2019 21:04:50 +0000 (23:04 +0200)
gimp_passport_plugin.py

index 8b6f92a..d7ecf11 100755 (executable)
@@ -9,16 +9,16 @@ def create_passport(image, drawable, paper_height_mm, paper_width_mm):
     # image = gimp.image_list()[0]
     # drawable = pdb.gimp_image_get_active_drawable(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[:, :])
-
     # get face extent
     non_empty, left, top, right, bottom = pdb.gimp_selection_bounds(image)
     if not non_empty:
         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)