-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello_warning.py
More file actions
176 lines (136 loc) · 5.37 KB
/
Copy pathhello_warning.py
File metadata and controls
176 lines (136 loc) · 5.37 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env python
# Tutorial available at: https://www.youtube.com/watch?v=nmb-0KcgXzI
from gimpfu import *
def hello_warning(image, drawable, image2):
if image:
pdb.gimp_message("current image: " + image.name )
# insert the alpha channel
layer = image.active_layer
pdb.gimp_layer_add_alpha(layer)
# crop the image
new_width = 410
new_height = 250
offx = 118 + 14
offy = 322 + 12
pdb.gimp_image_crop(image, new_width, new_height, offx, offy)
# adjust the perspective
drawable = image.active_layer
# upper left
x0 = 0
y0 = 0
# upper right
x1 = new_width
y1 = -10
# lower left
x2 = 0
y2 = 250
# lower right
x3 = new_width
y3 = new_height
transform_direction = 0 #TRANSFORM-FORWARD
interpolation = 2 #INTERPOLATION-CUBIC
supersample = 0 #ignored parameter
recursion_level = 3
clip_result = 1 #TRANSFORM-RESIZE-CLIP
drawable = pdb.gimp_drawable_transform_perspective(drawable, x0, y0, x1, y1, x2, y2, x3, y3, transform_direction, interpolation, supersample, recursion_level, clip_result)
# select the white stuff
operation = CHANNEL_OP_REPLACE
color = (235, 255, 255)
sample_threshold = 60.0/255.0
pdb.gimp_context_set_sample_threshold(sample_threshold)
pdb.gimp_image_select_color(image, operation, drawable, color)
# set FG Color to white
foreground = (255, 255, 255)
pdb.gimp_context_set_foreground(foreground)
# color selection white
fill_mode = FG_BUCKET_FILL
paint_mode = NORMAL_MODE
opacity = 100
threshold = 0
sample_merged = 0
x = 0
y = 0
pdb.gimp_bucket_fill(drawable, fill_mode, paint_mode, opacity, threshold, sample_merged, x, y)
# invert selection
pdb.gimp_selection_invert(image)
# delete stuff
pdb.gimp_edit_clear(drawable)
# invert selection again
pdb.gimp_selection_invert(image)
# make selection bigger
steps = 3
pdb.gimp_selection_grow(image, steps)
# create new layer
width = image.active_layer.width
height = image.active_layer.height
type = RGBA_IMAGE
name = "text background"
opacity = 100
mode = NORMAL_MODE
layer_textbg = pdb.gimp_layer_new(image, width, height, type, name, opacity, mode)
position = 1
pdb.gimp_image_add_layer(image, layer_textbg, position)
# # select layer
image.active_layer = layer_textbg
# set FG Color to black
foreground = (0, 0, 0)
pdb.gimp_context_set_foreground(foreground)
# fill selection with black
fill_mode = FG_BUCKET_FILL
paint_mode = NORMAL_MODE
opacity = 100
threshold = 0
sample_merged = 0
x = 0
y = 0
pdb.gimp_bucket_fill(layer_textbg, fill_mode, paint_mode, opacity, threshold, sample_merged, x, y)
# select layer '0
merge_layer = image.layers[0]
merge_type = EXPAND_AS_NECESSARY
layer = pdb.gimp_image_merge_down(image, merge_layer, merge_type)
# select all
pdb.gimp_selection_all(image)
# copy
drawable = image.active_layer
non_empty = pdb.gimp_edit_copy(drawable)
if non_empty:
pdb.gimp_message("copy successful" )
# create a new layer in the second image
width = new_width
height = new_height
type = RGBA_IMAGE
name = "information text"
opacity = 100
mode = NORMAL_MODE
layer_info = pdb.gimp_layer_new(image2, width, height, type, name, opacity, mode)
position = 0
pdb.gimp_image_add_layer(image2, layer_info, position)
# paste image
drawable = image2.active_layer
paste_into = True
floating_sel = pdb.gimp_edit_paste(drawable, paste_into)
pdb.gimp_floating_sel_anchor(floating_sel)
else:
pdb.gimp_message("No image loaded")
register(
"python-fu-Hello-Warning",
"simply a test",
"simply a test but longer description",
"Me", "Myself", "2018",
"Hello warning",
"", # type of image it works on (*, RGB, RGB*, RGBA, GRAY etc...)
[
# basic parameters are: (UI_ELEMENT, "variable", "label", Default)
(PF_IMAGE, "image", "takes current image", None),
(PF_DRAWABLE, "drawable", "Input layer", None),
(PF_IMAGE, "image2", "Select image where to paste the information", None)
# PF_SLIDER, SPINNER have an extra tuple (min, max, step)
# PF_RADIO has an extra tuples within a tuple:
# eg. (("radio_label", "radio_value), ...) for as many radio buttons
# PF_OPTION has an extra tuple containing options in drop-down list
# eg. ("opt1", "opt2", ...) for as many options
# see ui_examples_1.py and ui_examples_2.py for live examples
],
[],
hello_warning, menu="<Image>/My scripts") # second item is menu location
main()