-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathweahtr_guides.py
executable file
·65 lines (54 loc) · 1.71 KB
/
weahtr_guides.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
import math
from gimpfu import *
import os
def weahtr_save_guides(image, directory_name, filename):
# open session
pdb.gimp_context_push()
# create list elements to store guide details
rows = []
cols = []
# collect all guide values
index = pdb.gimp_image_find_next_guide(image,0)
while index > 0:
if pdb.gimp_image_get_guide_orientation(image, index) == ORIENTATION_HORIZONTAL:
rows.append(pdb.gimp_image_get_guide_position(image, index))
else:
cols.append(pdb.gimp_image_get_guide_position(image, index))
# increment guide index
index = pdb.gimp_image_find_next_guide(image, index)
# sort the values incrementally
rows = sorted(rows)
cols = sorted(cols)
# convert to strings
img_name = '"filename" : "{}"'.format(os.path.basename(image.filename))
rows = '"rows" : [{}]'.format(','.join(map(str,rows)))
cols = '"cols" : [{}]'.format(','.join(map(str,cols)))
# save file as json format, manually formatted
# to avoid too many libraries
savefile = open( u'' + os.path.join(directory_name, filename), 'w')
guide_str_data = "{" + img_name + "," + rows + "," + cols + "}"
savefile.write(guide_str_data + "\n")
savefile.close()
# close session
pdb.gimp_context_pop()
pdb.gimp_displays_flush()
register(
"python_fu_weahtr_save_guides",
"Saves a set of weahtr guides",
"Saves a set of weahtr guides...",
"Koen Hufkens",
"Koen Hufkens",
"2024",
"weahtr - Save guides...",
"*",
[
(PF_IMAGE, "image", "takes current image", None),
(PF_DIRNAME, "directory_name", "Directory:", "/tmp"),
(PF_STRING, "filename", "Guides Name:", "weahtr.json"),
],
[],
weahtr_save_guides,
menu="<Image>/Image/Guides"
)
main()