forked from akkana/gimp-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcutout.py
executable file
·81 lines (66 loc) · 2.72 KB
/
cutout.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python
# Cut out a selected band an image, either vertically or horizontally,
# resizing the canvas appropriately afterward.
# The selection must extend all the way across the image either
# vertically or horizontally, but not both.
from gimpfu import *
def python_fu_cutout(img, drawable):
pdb.gimp_message_set_handler(MESSAGE_BOX)
exists, x1, y1, x2, y2 = pdb.gimp_selection_bounds(img)
orient = None
# Figure out whether we're cutting vertically or horizontally.
# It's ridiculously hard to make a selectin exactly the width or
# height of the image, so figure that 95% is close enough.
thresh = .05
if x1 < thresh * img.width and x2 > img.width * (1. - thresh):
orient = 'h'
if y1 <= thresh * img.height and y2 > img.height * (1. - thresh):
if orient:
pdb.gimp_message("Error: selection can't encompass entire image")
return
orient = 'v'
if not orient:
pdb.gimp_message("Must have a selection spanning entire width or height")
print "Selection is %d-%d x %d-%d" % (x1, x2, y1, y2)
return
# Now orient is either 'h' or 'v'.
img.undo_group_start()
if orient == 'h':
pdb.gimp_image_select_rectangle(img, CHANNEL_OP_REPLACE,
0, y2, img.width, img.height)
pdb.gimp_edit_cut(drawable)
pdb.gimp_image_select_rectangle(img, CHANNEL_OP_REPLACE,
0, y1, img.width, img.height - y2)
flayer = pdb.gimp_edit_paste(drawable, True)
pdb.gimp_floating_sel_anchor(flayer)
pdb.gimp_image_resize(img, img.width, y1 + img.height - y2, 0, 0)
pdb.gimp_selection_none(img)
elif orient == 'v':
pdb.gimp_image_select_rectangle(img, CHANNEL_OP_REPLACE,
x2, 0, img.width - x2, img.height)
pdb.gimp_edit_cut(drawable)
pdb.gimp_image_select_rectangle(img, CHANNEL_OP_REPLACE,
x1, 0, img.width - x2, img.height)
flayer = pdb.gimp_edit_paste(drawable, True)
pdb.gimp_floating_sel_anchor(flayer)
pdb.gimp_image_resize(img, x1 + img.width - x2, img.height, 0, 0)
pdb.gimp_selection_none(img)
img.undo_group_end()
register(
"python_fu_cutout",
"Cut a selected band from an image, either vertically or horizontally",
"Cut a selected band from an image, either vertically or horizontally",
"Akkana Peck",
"Akkana Peck",
"2013",
"Cut out selected band",
"*",
[
(PF_IMAGE, "image", "Input image", None),
(PF_DRAWABLE, "drawable", "Input drawable", None),
],
[],
python_fu_cutout,
menu = "<Image>/Filters/Distorts/"
)
main()