Expose parameter fpr (face to picture ratio).
[toast/gimp_passport.git] / gimp_passport_plugin.py
1 #!/usr/bin/python
2
3 from gimpfu import *
4 import PIL.Image
5 import gimp_passport
6
7
8 def create_passport(image, drawable, paper_height_mm, paper_width_mm, fpr):
9     # Note: for interactive sessions you can get the image via:
10     # image = gimp.image_list()[0]
11     # drawable = pdb.gimp_image_get_active_drawable(image)
12
13     # get face extent
14     non_empty, left, top, right, bottom = pdb.gimp_selection_bounds(image)
15     if not non_empty:
16         pdb.gimp_message('Please select the face first.')
17         return image
18
19     # pdb.gimp_image_find_next_guide(image, 0)
20     # pdb.gimp_image_get_guide_orientation(image, 6)
21     # pdb.gimp_image_get_guide_position(image, 6)
22
23     photo_width_mm = 35.
24     photo_height_mm = 45.
25     margin_mm = 4.
26     spacing_mm = 1.
27
28     # convert GIMP image to PIL image:
29     rgn = drawable.get_pixel_rgn(0, 0, drawable.width, drawable.height)
30     pil_img = PIL.Image.frombytes('RGB', (drawable.width, drawable.height), rgn[:, :])
31
32     # perform processing
33     pil_paper = gimp_passport.process(paper_width_mm, paper_height_mm, margin_mm, photo_width_mm, photo_height_mm, spacing_mm, 
34                                       fpr, None, (left, top, right, bottom), pil_img)
35
36     # copy processed PIL to new GIMP image
37     image_new = pdb.gimp_image_new(pil_paper.width, pil_paper.height, pdb.gimp_image_base_type(image))
38     layer = gimp.Layer(image_new, "passport", pil_paper.width, pil_paper.height, pdb.gimp_image_base_type(image), 100, NORMAL_MODE)
39     image_new.add_layer(layer)
40     rgn = layer.get_pixel_rgn(0, 0, layer.width, layer.height, True)
41     rgn[:, :] = pil_paper.tobytes()
42     gimp.Display(image_new)
43     return image_new
44
45
46 register(
47         "create_passport",
48         "Creates a printable passport image (contact sheet) from a photo",
49         "Select the face and call the plugin",
50         "Toastfreeware",
51         "Toastfreeware",
52         "2019",
53         "<Image>/Filters/Map/Create _Passport...",
54         "RGB*, GRAY*",
55         [
56             (PF_INT, "paper_height_mm", "Paper height in mm", 100),
57             (PF_INT, "paper_width_mm", "Paper width in mm", 150),
58             (PF_FLOAT, "fpr", "Face to picture ratio", 0.75),
59         ],
60         [
61             (PF_IMAGE, "image", "passport image for printout"),
62         ],
63         create_passport)
64
65
66 main()
67