-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFU_edges_trans-border.scm
228 lines (190 loc) · 7.96 KB
/
FU_edges_trans-border.scm
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
; FU_edges_trans-border.scm
; version 2.8 [gimphelp.org]
; last modified/tested by Paul Sherman
; 02/03/2014 on GIMP-2.8.10
; 03/09/2020 on GIMP-2.10.20
;
;==============================================================
;
; Installation:
; This script should be placed in the user or system-wide script folder.
;
; Windows Vista/7/8)
; C:\Program Files\GIMP 2\share\gimp\2.0\scripts
; or
; C:\Users\YOUR-NAME\.gimp-2.8\scripts
;
; Windows XP
; C:\Program Files\GIMP 2\share\gimp\2.0\scripts
; or
; C:\Documents and Settings\yourname\.gimp-2.8\scripts
;
; Linux
; /home/yourname/.gimp-2.8/scripts
;
; Linux system-wide
; /usr/share/gimp/2.0/scripts
;
;==============================================================
;
; LICENSE
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <http://www.gnu.org/licenses/>.
;
;==============================================================
; Original information
;
; Translucent Border is a script for The GIMP
; Creates a border with reduced brightness and 2 inner colours.
; The script is located in menu "<Image>/Script-Fu/Edges/Translucent Border"
; Last changed: 7 August 2007
;
; Copyright (C) 2007 Harry Phillips <[email protected]>
;==============================================================
(define (FU-trans-border
theImage
theLayer
innerColour
innerSize
outerColour
outerSize
borderType
borderSize
borderPercent
borderBrightness
)
(let* (
;Read the current colours
(myForeground (car (gimp-context-get-foreground)))
(myBackground (car (gimp-context-get-background)))
;Read the image width and height
(imageWidth (car (gimp-image-width theImage)))
(imageHeight (car (gimp-image-height theImage)))
(selectWidth 0)
(selectHeight 0)
(outerLayer 0)
(innerLayer 0)
(mask 0)
(co-ord 0)
(sizeBAD FALSE)
(copyBack)
)
;Calculate the selection sizes
(if (= borderType 0)
;Set the co-ord to the pixel size
(set! co-ord borderSize)
(begin
;Set the co-ord to a percentage of the shortest side
(if (> imageWidth imageHeight)
(set! co-ord (/ (* imageHeight borderPercent) 100))
(set! co-ord (/ (* imageWidth borderPercent) 100))
)
)
)
;Check the width
(if (< imageWidth (+ innerSize (+ outerSize (* 2 borderSize))))
(begin
(set! sizeBAD TRUE)
)
()
)
;Check the height
(if (< imageHeight (+ innerSize (+ outerSize (* 2 borderSize))))
(begin
(set! sizeBAD TRUE)
)
()
)
;Give an error message if the size is not ok
(if (= sizeBAD TRUE)
(begin
(gimp-message "The image is not large enough for that border size")
)
(begin
;Start an undo group so the process can be undone with one undo
(gimp-image-undo-group-start theImage)
;Copy the layer
(set! copyBack (car (gimp-layer-copy theLayer 1)))
;Select none
(gimp-selection-none theImage)
;Set the foreground and background colours
(gimp-context-set-foreground outerColour)
(gimp-context-set-background innerColour)
;Add the first layer to the image
(gimp-image-insert-layer theImage copyBack 0 0)
;Rename the layer
(gimp-item-set-name copyBack "Original")
;Set the brightness of the background layer
(gimp-brightness-contrast theLayer borderBrightness 0)
;Calculate the selection size
(set! selectWidth (- imageWidth (* co-ord 2)))
(set! selectHeight (- imageHeight (* co-ord 2)))
;Select the first part
(gimp-image-select-rectangle theImage CHANNEL-OP-REPLACE co-ord co-ord selectWidth selectHeight)
;Add the outer layer
(set! outerLayer (car (gimp-layer-new theImage imageWidth imageHeight 1 "Outer" 100 0)))
(gimp-image-insert-layer theImage outerLayer 0 1)
;Fill the layer with FG colour
(gimp-edit-fill outerLayer 0)
;Add a layer mask
(set! mask (car (gimp-layer-create-mask outerLayer 4)))
(gimp-layer-add-mask outerLayer mask)
;Add the inner layer(car (gimp-context-get-foreground))
(set! innerLayer (car (gimp-layer-new theImage imageWidth imageHeight 1 "Inner" 100 0)))
(gimp-image-insert-layer theImage innerLayer 0 1)
;Fill the layer with BG colour
(gimp-edit-fill innerLayer 1)
;Reduce the selection by the outer amount
(gimp-selection-shrink theImage outerSize)
;Add a layer mask
(set! mask (car (gimp-layer-create-mask innerLayer 4)))
(gimp-layer-add-mask innerLayer mask)
;Reduce the selection by the inner amount
(gimp-selection-shrink theImage innerSize)
;Add a layer mask to the original
(set! mask (car (gimp-layer-create-mask copyBack 4)))
(gimp-layer-add-mask copyBack mask)
;Select none
(gimp-selection-none theImage)
;Set the FG and BG colours back to what they were
(gimp-context-set-foreground myForeground)
(gimp-context-set-background myBackground)
;Finish the undo group for the process
(gimp-image-undo-group-end theImage)
;Ensure the updated image is displayed now
(gimp-displays-flush)
)
)
)
)
(script-fu-register "FU-trans-border"
"Translucent Border"
"Gives a transparent border with two inner lines. \nfile:FU_edges_trans-border.scm"
"Harry Phillips"
"Harry Phillips"
"Mar. 16 2007"
"*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Drawable" 0
SF-COLOR "Inner colour" '(255 255 255)
SF-ADJUSTMENT "Inner size" '(5 0 50 1 1 0 0)
SF-COLOR "Outer colour" '(0 0 0)
SF-ADJUSTMENT "Outer size" '(5 0 50 1 1 0 0)
SF-OPTION "Border type" '("Pixels" "Percentage")
SF-ADJUSTMENT "Border pixels" '(150 0 1000 1 1 0 0)
SF-ADJUSTMENT "Border percentage" '(10 0 100 1 1 0 0)
SF-ADJUSTMENT "Border brightness" '(-80 -127 0 1 1 0 1)
)
(script-fu-menu-register "FU-trans-border" "<Toolbox>/Script-Fu/Edges/")
; end of script