-
-
Notifications
You must be signed in to change notification settings - Fork 988
/
rmtrans.py
executable file
·41 lines (37 loc) · 1.57 KB
/
rmtrans.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
#!/usr/bin/env python2
from gimpfu import *
def rmtrans(img,tdrawable):
pdb.gimp_image_undo_group_start(img)
if pdb.gimp_selection_is_empty(img):
pdb.gimp_selection_all(img)
selection = pdb.gimp_selection_save(img)
pdb.gimp_selection_none(img)
alpha,temp,temp,temp = pdb.plug_in_decompose(img,tdrawable,"Alpha",1) # get alpha channel
alpha = pdb.gimp_image_get_active_layer(alpha) # turn it into a layer
pdb.gimp_edit_copy(alpha)
pdb.gimp_floating_sel_to_layer(pdb.gimp_edit_paste(tdrawable,TRUE))
alpha = pdb.gimp_image_get_active_layer(img) # move alpha layer into image (copy-paste)
pdb.gimp_context_set_antialias(False)
pdb.gimp_context_set_sample_threshold(0.0) # configuration for color selection
for i in xrange(10):
pdb.gimp_image_select_color(img,CHANNEL_OP_REPLACE,alpha,(i,i,i)) # select alpha values <= 10
pdb.gimp_image_select_item(img,CHANNEL_OP_INTERSECT,selection) # bound it to the previously selected area (before plugin execution)
if not(pdb.gimp_selection_is_empty(img)):
pdb.gimp_edit_clear(tdrawable) # and clear it
print(alpha)
pdb.gimp_image_remove_layer(img,alpha)
pdb.gimp_selection_none(img)
pdb.gimp_image_undo_group_end(img)
register(
"python_fu_rmtrans",
"Remove all pixels under a given alpha threshold.",
"Remove all pixels under a given alpha threshold.",
"Samuel Kim",
"Samuel Kim",
"2012",
"<Image>/Colors/Remove almost-transparent pixels",
"*",
[],
[],
rmtrans)
main()