28
28
; Copyright (C) 1997-1999 Sven Neumann <sven@gimp.org>
31
; Adds a drop-shadow of the current selection or alpha-channel.
33
; This script is derived from my script add-shadow, which has become
34
; obsolete now. Thanks to Andrew Donkin (ard@cs.waikato.ac.nz) for his
31
; Adds a drop-shadow of the current selection or alpha-channel.
33
; This script is derived from my script add-shadow, which has become
34
; obsolete now. Thanks to Andrew Donkin (ard@cs.waikato.ac.nz) for his
35
35
; idea to add alpha-support to add-shadow.
38
38
(define (script-fu-drop-shadow image
46
(let* ((shadow-blur (max shadow-blur 0))
47
(shadow-opacity (min shadow-opacity 100))
48
(shadow-opacity (max shadow-opacity 0))
49
(type (car (gimp-drawable-type-with-alpha drawable)))
50
(image-width (car (gimp-image-width image)))
51
(image-height (car (gimp-image-height image)))
58
(gimp-image-set-active-layer image drawable)
60
(gimp-image-undo-group-start image)
62
(gimp-layer-add-alpha drawable)
63
(if (= (car (gimp-selection-is-empty image)) TRUE)
65
(gimp-selection-layer-alpha drawable)
66
(set! from-selection FALSE))
68
(set! from-selection TRUE)
69
(set! active-selection (car (gimp-selection-save image)))))
71
(let* ((selection-bounds (gimp-selection-bounds image))
72
(select-offset-x (cadr selection-bounds))
73
(select-offset-y (caddr selection-bounds))
74
(select-width (- (cadr (cddr selection-bounds)) select-offset-x))
75
(select-height (- (caddr (cddr selection-bounds)) select-offset-y))
77
(shadow-width (+ select-width (* 2 shadow-blur)))
78
(shadow-height (+ select-height (* 2 shadow-blur)))
80
(shadow-offset-x (- select-offset-x shadow-blur))
81
(shadow-offset-y (- select-offset-y shadow-blur)))
83
(if (= allow-resize TRUE)
84
(let* ((new-image-width image-width)
85
(new-image-height image-height)
89
(if (< (+ shadow-offset-x shadow-transl-x) 0)
91
(set! image-offset-x (- 0 (+ shadow-offset-x
93
(set! shadow-offset-x (- 0 shadow-transl-x))
94
(set! new-image-width (- new-image-width image-offset-x))))
96
(if (< (+ shadow-offset-y shadow-transl-y) 0)
98
(set! image-offset-y (- 0 (+ shadow-offset-y
100
(set! shadow-offset-y (- 0 shadow-transl-y))
101
(set! new-image-height (- new-image-height image-offset-y))))
103
(if (> (+ (+ shadow-width shadow-offset-x) shadow-transl-x)
105
(set! new-image-width
106
(+ (+ shadow-width shadow-offset-x) shadow-transl-x)))
108
(if (> (+ (+ shadow-height shadow-offset-y) shadow-transl-y)
110
(set! new-image-height
111
(+ (+ shadow-height shadow-offset-y) shadow-transl-y)))
113
(gimp-image-resize image
119
(set! shadow-layer (car (gimp-layer-new image
126
(gimp-image-add-layer image shadow-layer -1)
127
(gimp-layer-set-offsets shadow-layer
131
(gimp-drawable-fill shadow-layer TRANSPARENT-FILL)
132
(gimp-context-set-background shadow-color)
133
(gimp-edit-fill shadow-layer BACKGROUND-FILL)
134
(gimp-selection-none image)
135
(gimp-layer-set-preserve-trans shadow-layer FALSE)
136
(if (>= shadow-blur 1.0) (plug-in-gauss-rle 1
142
(gimp-layer-translate shadow-layer shadow-transl-x shadow-transl-y)
144
(if (= from-selection TRUE)
146
(gimp-selection-load active-selection)
147
(gimp-edit-clear shadow-layer)
148
(gimp-image-remove-channel image active-selection)))
151
(= (car (gimp-layer-is-floating-sel drawable)) 0)
152
(= from-selection FALSE))
153
(gimp-image-raise-layer image drawable))
155
(gimp-image-set-active-layer image drawable)
156
(gimp-image-undo-group-end image)
157
(gimp-displays-flush)
47
(shadow-blur (max shadow-blur 0))
48
(shadow-opacity (min shadow-opacity 100))
49
(shadow-opacity (max shadow-opacity 0))
50
(type (car (gimp-drawable-type-with-alpha drawable)))
51
(image-width (car (gimp-image-width image)))
52
(image-height (car (gimp-image-height image)))
60
(gimp-image-set-active-layer image drawable)
62
(gimp-image-undo-group-start image)
64
(gimp-layer-add-alpha drawable)
65
(if (= (car (gimp-selection-is-empty image)) TRUE)
67
(gimp-selection-layer-alpha drawable)
68
(set! from-selection FALSE))
70
(set! from-selection TRUE)
71
(set! active-selection (car (gimp-selection-save image)))))
73
(let* ((selection-bounds (gimp-selection-bounds image))
74
(select-offset-x (cadr selection-bounds))
75
(select-offset-y (caddr selection-bounds))
76
(select-width (- (cadr (cddr selection-bounds)) select-offset-x))
77
(select-height (- (caddr (cddr selection-bounds)) select-offset-y))
79
(shadow-width (+ select-width (* 2 shadow-blur)))
80
(shadow-height (+ select-height (* 2 shadow-blur)))
82
(shadow-offset-x (- select-offset-x shadow-blur))
83
(shadow-offset-y (- select-offset-y shadow-blur)))
85
(if (= allow-resize TRUE)
86
(let* ((new-image-width image-width)
87
(new-image-height image-height)
91
(if (< (+ shadow-offset-x shadow-transl-x) 0)
93
(set! image-offset-x (- 0 (+ shadow-offset-x
95
(set! shadow-offset-x (- 0 shadow-transl-x))
96
(set! new-image-width (- new-image-width image-offset-x))))
98
(if (< (+ shadow-offset-y shadow-transl-y) 0)
100
(set! image-offset-y (- 0 (+ shadow-offset-y
102
(set! shadow-offset-y (- 0 shadow-transl-y))
103
(set! new-image-height (- new-image-height image-offset-y))))
105
(if (> (+ (+ shadow-width shadow-offset-x) shadow-transl-x)
107
(set! new-image-width
108
(+ (+ shadow-width shadow-offset-x) shadow-transl-x)))
110
(if (> (+ (+ shadow-height shadow-offset-y) shadow-transl-y)
112
(set! new-image-height
113
(+ (+ shadow-height shadow-offset-y) shadow-transl-y)))
115
(gimp-image-resize image
123
(set! shadow-layer (car (gimp-layer-new image
130
(gimp-image-add-layer image shadow-layer -1)
131
(gimp-layer-set-offsets shadow-layer
135
(gimp-drawable-fill shadow-layer TRANSPARENT-FILL)
136
(gimp-context-set-background shadow-color)
137
(gimp-edit-fill shadow-layer BACKGROUND-FILL)
138
(gimp-selection-none image)
139
(gimp-layer-set-lock-alpha shadow-layer FALSE)
140
(if (>= shadow-blur 1.0) (plug-in-gauss-rle 1
146
(gimp-layer-translate shadow-layer shadow-transl-x shadow-transl-y)
148
(if (= from-selection TRUE)
150
(gimp-selection-load active-selection)
151
(gimp-edit-clear shadow-layer)
152
(gimp-image-remove-channel image active-selection)))
155
(= (car (gimp-layer-is-floating-sel drawable)) 0)
156
(= from-selection FALSE))
157
(gimp-image-raise-layer image drawable))
159
(gimp-image-set-active-layer image drawable)
160
(gimp-image-undo-group-end image)
161
(gimp-displays-flush)
161
167
(script-fu-register "script-fu-drop-shadow"
163
"Add a drop-shadow of the current selection or alpha-channel"
164
"Sven Neumann <sven@gimp.org>"
169
SF-DRAWABLE "Drawable" 0
170
SF-ADJUSTMENT _"Offset X" '(8 -4096 4096 1 10 0 1)
171
SF-ADJUSTMENT _"Offset Y" '(8 -4096 4096 1 10 0 1)
172
SF-ADJUSTMENT _"Blur radius" '(15 0 1024 1 10 0 1)
173
SF-COLOR _"Color" '(0 0 0)
174
SF-ADJUSTMENT _"Opacity" '(80 0 100 1 10 0 0)
175
SF-TOGGLE _"Allow resizing" TRUE)
169
_"Add a drop shadow to the selected region (or alpha)"
170
"Sven Neumann <sven@gimp.org>"
175
SF-DRAWABLE "Drawable" 0
176
SF-ADJUSTMENT _"Offset X" '(8 -4096 4096 1 10 0 1)
177
SF-ADJUSTMENT _"Offset Y" '(8 -4096 4096 1 10 0 1)
178
SF-ADJUSTMENT _"Blur radius" '(15 0 1024 1 10 0 1)
179
SF-COLOR _"Color" "black"
180
SF-ADJUSTMENT _"Opacity" '(80 0 100 1 10 0 0)
181
SF-TOGGLE _"Allow resizing" TRUE
177
184
(script-fu-menu-register "script-fu-drop-shadow"
178
_"<Image>/Script-Fu/Shadow")
185
"<Image>/Filters/Light and Shadow/Shadow")