-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFU_edges_fade-outline.scm
212 lines (201 loc) · 7.89 KB
/
FU_edges_fade-outline.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
; FU_edges_fade-outline.scm
; version 2.8 [gimphelp.org]
; last modified/tested by Paul Sherman
; 02/14/2014 on GIMP-2.8.10
; 22/07/2020 on Gimp-2.10.20
;
; 10/17/2010 - fixed undefined variable (old-selection)
; when using a growing selection. Discovered and
; corrected by John McGowan <jmcgowan@inch.com>
; 02/14/2014 - convert to RGB if needed
;==============================================================
;
; Installation:
; This script should be placed in the user or system-wide script folder.
;
; Windows 10
; C:\Program Files\GIMP 2\share\gimp\2.0\scripts
; or
; C:\Users\YOUR-NAME\.gimp-2.10\scripts
; or
; C:\Documents and Settings\yourname\.gimp-2.8\scripts
;
; Linux
; /home/yourname/.gimp-2.8/scripts
; or
; 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
;
; This GIMP script_fu operates on a single Layer
; It blends the outline boarder from one to another transparency level
; by adding a layer_mask that follows the shape of the selection.
; usually from 100% (white is full opaque) to 0% (black is full transparent)
;
; The user can specify the thickness of the fading border
; that is used to blend from transparent to opaque
; and the Fading direction (shrink or grow).
;
; The outline is taken from the current selection
; or from the layers alpha channel if no selection is active.
;
; Optional you may keep the generated layermask or apply
; it to the layer
;
; Tue 10/14/2008 - Modified by Paul Sherman
; Eliminated undefined variable errors.
; Simplified by flattening image upon completion.
; Added option to leave fade transparent, or flaten onto the image.
;==============================================================
(define (FU-fade-outline
inImage
inLayer
inBorderSize
inFadeFrom
inFadeTo
inLeaveTransparent
)
(let* (
(l-idx 0)
(l-old-bg-color (car (gimp-context-get-background)))
(l-has-selection TRUE)
(width (car (gimp-image-width inImage)))
(height (car (gimp-image-height inImage)))
(backgroundlayer (car (gimp-layer-new inImage width height RGBA-IMAGE "Background Layer" 100 LAYER-MODE-NORMAL)))
)
; check Fade from and To Values (and force values from 0% to 100%)
(if (> inFadeFrom 100)
(begin
(set! inFadeFrom 100 )
)
)
(if (< inFadeFrom 0)
(begin
(set! inFadeFrom 0 )
)
)
(if (> inFadeTo 100)
(begin
(set! inFadeTo 100 )
)
)
(if (< inFadeTo 0)
(begin
(set! inFadeTo 0 )
)
)
(define l-from-gray (* inFadeFrom 255))
(define l-to-gray (* inFadeTo 255))
(define l-step (/ (- l-from-gray l-to-gray) (+ inBorderSize 1)))
(define l-gray l-to-gray)
(define old-selection)
; do nothing if the layer is a layer mask
(if (= (car (gimp-item-is-layer-mask inLayer)) 0)
(begin
(gimp-image-undo-group-start inImage)
(if (not (= RGB (car (gimp-image-base-type inImage))))
(gimp-image-convert-rgb inImage)
)
; if the layer has no alpha add alpha channel
(if (= (car (gimp-drawable-has-alpha inLayer)) FALSE)
(begin
(gimp-layer-add-alpha inLayer)
)
)
; if the layer is the floating selection convert to normal layer
; because floating selection cant have a layer mask
(if (> (car (gimp-layer-is-floating-sel inLayer)) 0)
(begin
(gimp-floating-sel-to-layer inLayer)
)
)
; if there is no selection we use the layers alpha channel
(if (= (car (gimp-selection-is-empty inImage)) TRUE)
(begin
(set! l-has-selection FALSE)
(gimp-image-select-item inImage CHANNEL-OP-REPLACE inLayer)
)
)
(gimp-selection-sharpen inImage)
(define l-mask (car (gimp-layer-create-mask inLayer ADD-MASK-WHITE)))
(gimp-layer-add-mask inLayer l-mask)
(while (<= l-idx inBorderSize)
(if (= l-idx inBorderSize)
(begin
(set! l-gray l-from-gray)
)
)
;(gimp-message "x")
;(gimp-message (number->string (round (/ l-gray 100))))
(gimp-context-set-background (list (round (/ l-gray 100)) (round (/ l-gray 100)) (round (/ l-gray 100))))
(gimp-edit-fill l-mask FILL-BACKGROUND)
(set! l-idx (+ l-idx 1))
(set! l-gray (+ l-gray l-step))
(gimp-selection-shrink inImage 1)
; check if selection has shrinked to none
(if (= (car (gimp-selection-is-empty inImage)) TRUE)
(begin
(set! l-idx (+ inBorderSize 100)) ; break the while loop
)
)
)
(if (= l-has-selection FALSE)
(begin
(gimp-selection-none inImage)
)
)
(gimp-context-set-background l-old-bg-color)
(gimp-selection-none inImage)
(if (= inLeaveTransparent TRUE)
(begin
(gimp-image-flatten inImage)
)
(begin
;add a background
(gimp-image-insert-layer inImage backgroundlayer 0 1)
;(gimp-context-set-background '(0 0 0))
(gimp-edit-fill backgroundlayer FILL-BACKGROUND)
)
)
(gimp-displays-flush)
(gimp-image-undo-group-end inImage)
)
)
)
)
(script-fu-register
"FU-fade-outline"
"Fade Outline"
"Blend the Layers outline border from one alpha value (opaque) to another (transparent) by generating a Layermask. \nfile:FU_edges_fade-outline.scm"
"Wolfgang Hofer <hof@hotbot.com>"
"Wolfgang Hofer"
"10 Nov 1999"
"*"
SF-IMAGE "The Image" 0
SF-DRAWABLE "The Layer" 0
SF-ADJUSTMENT "Border Size" '(10 1 300 1 10 0 1)
SF-ADJUSTMENT "Fade From %" '(100 0 100 1 10 0 0)
SF-ADJUSTMENT "Fade To %" '(0 0 100 1 10 0 0)
SF-TOGGLE "Leave faded area transparent / Flatten" FALSE
)
(script-fu-menu-register "FU-fade-outline" "<Toolbox>/Script-Fu/Edges/")
; end of script