Skip to content

Commit 3781ed4

Browse files
authored
Snow adjustment added to ensure snow on letters
1 parent 43df3b2 commit 3781ed4

File tree

1 file changed

+160
-39
lines changed

1 file changed

+160
-39
lines changed

Snow Cover.scm

Lines changed: 160 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
; Rel 0.01 - Initial Release
2424
; Rel 0.02 - Added Alpha-to-Logo script, Improved Logo script, and changed name to Snow Cover.scm
2525
; Rel 0.03 - Updated to Gimp-2.10.22
26+
; Rel 0.04 - Updated to GIMP-2.10.36 on 2/12/2023
2627
;
2728
; Gradients blend direction list
2829
(define list-blend-dir '("Left to Right" "Top to Bottom" "Diagonal to centre" "Diagonal from centre"))
@@ -41,6 +42,7 @@
4142
;
4243
(define (script-fu-snow-cover-alpha image layer
4344
depth
45+
snowupdown
4446
conserve
4547
)
4648

@@ -55,26 +57,44 @@
5557
(snowtop-layer 0)
5658
(snowshadow-layer 0)
5759
(ver 2.8)
60+
(adjustoffset 1)
61+
(calcoffset 0)
5862
)
63+
;(gimp-message "Snow cover alpha start")
64+
(gimp-progress-pulse)
5965
(cond ((not (defined? 'gimp-image-get-item-position)) (set! ver 2.6))) ;define the gimp version
6066

6167
(gimp-context-push)
6268
(gimp-context-set-paint-method "gimp-paintbrush")
63-
(cond ((defined? 'gimp-context-set-dynamics) (gimp-context-set-dynamics "Dynamics Off")))
69+
;(cond ((defined? 'gimp-context-set-dynamics) (gimp-context-set-dynamics "Dynamics Off")))
70+
(gimp-context-set-dynamics "Dynamics Off")
6471
(gimp-context-set-foreground '(0 0 0))
6572
(gimp-context-set-background '(255 255 255))
6673

67-
;;;;begin the script
74+
;;;;begin the script
6875
(cond ((= ver 2.8) (gimp-image-select-item image 2 layer))
6976
(else (gimp-selection-layer-alpha layer))
70-
) ;endcond
77+
) ;endcond
78+
79+
;(gimp-message "line74")
80+
;(gimp-display-new image)
81+
;(gimp-displays-flush)
82+
;(quit)
83+
(gimp-progress-update 0.2)
84+
7185
(set! snow-layer (car (gimp-layer-new image width height RGBA-IMAGE "Snow Template" 100 LAYER-MODE-NORMAL)))
7286
(include-layer image snow-layer layer 0) ;stack 0=above 1=below
7387
(gimp-edit-fill snow-layer FILL-BACKGROUND)
88+
89+
7490
(gimp-layer-set-offsets snow-layer 0 (- 0 depth))
7591
(gimp-edit-clear snow-layer)
7692
(gimp-selection-none image)
7793
(gimp-selection-layer-alpha snow-layer)
94+
95+
; optional grow the selection - make into another adjust value >0
96+
;(gimp-selection-grow image 2)
97+
;
7898
(script-fu-distress-selection image
7999
snow-layer
80100
127 ;Threshold (bigger 1<-->255 smaller)
@@ -83,27 +103,45 @@
83103
2 ;Smooth (2 1 150 1 10 0 1)
84104
TRUE ;Smooth horizontally TRUE
85105
TRUE) ;Smooth vertically TRUE
106+
107+
; alt distress
108+
;(script-fu-distress-selection image
109+
; snow-layer
110+
; 127 ;Threshold (bigger 1<-->255 smaller)
111+
; 2 ;Spread (8 0 1000 1 10 0 1)
112+
; 4 ;Granularity (1 is low) (4 1 25 1 10 0 1)
113+
; 2 ;Smooth (2 1 150 1 10 0 1)
114+
; TRUE ;Smooth horizontally TRUE
115+
; TRUE) ;Smooth vertically TRUE
116+
117+
118+
86119
(gimp-item-set-visible snow-layer FALSE)
87120

88121
(set! snowtop-layer (car (gimp-layer-new image width height RGBA-IMAGE "Snow Topping" 100 LAYER-MODE-NORMAL)))
89-
(include-layer image snowtop-layer snow-layer 0) ;stack 0=above 1=below
122+
(include-layer image snowtop-layer snow-layer 0) ;stack 0=above 1=below
90123
(gimp-context-set-background '(243 243 255))
91124
(gimp-edit-fill snowtop-layer FILL-BACKGROUND)
92125
(gimp-selection-none image)
93126
(plug-in-gauss-rle2 RUN-NONINTERACTIVE image snowtop-layer 3 3)
94127
(cond ((= ver 2.8)
95-
(gimp-context-set-sample-threshold-int 25)
96-
(gimp-context-set-antialias TRUE)
97-
(gimp-image-select-color image 2 snowtop-layer '(243 243 255)))
98-
(else (gimp-by-color-select snowtop-layer '(243 243 255) 25 2 TRUE FALSE 0 FALSE))
128+
(gimp-context-set-sample-threshold-int 55) ; was 25
129+
(gimp-context-set-antialias TRUE)
130+
(gimp-image-select-color image 2 snowtop-layer '(243 243 255))
131+
)
132+
(else (gimp-by-color-select snowtop-layer '(243 243 255) 25 2 TRUE FALSE 0 FALSE))
99133
) ;endcond
100134
(gimp-edit-fill snowtop-layer FILL-BACKGROUND)
101135

102136
(set! snowshadow-layer (car (gimp-layer-new image width height RGBA-IMAGE "Snow Shadow" 100 LAYER-MODE-NORMAL)))
103137
(include-layer image snowshadow-layer snowtop-layer 0) ;stack 0=above 1=below
104138
(gimp-context-set-background '(149 149 207))
105139
(gimp-edit-fill snowshadow-layer FILL-BACKGROUND)
106-
(gimp-layer-set-offsets snowshadow-layer 0 (/ depth 2))
140+
;(gimp-layer-set-offsets snowshadow-layer 0 (+ 0 5))
141+
(gimp-layer-set-offsets snowshadow-layer 0 (/ depth 2.0)) ; was depth/2
142+
;
143+
;(gimp-layer-set-offsets snowshadow-layer 0 snowupdown)
144+
107145
(gimp-edit-clear snowshadow-layer)
108146
(gimp-layer-set-offsets snowshadow-layer 0 -1)
109147
(gimp-selection-invert image)
@@ -113,8 +151,26 @@
113151
(gimp-selection-none image)
114152
(plug-in-gauss-rle2 RUN-NONINTERACTIVE image snowtop-layer 3 3)
115153

116-
;;;;finish the script
117-
(if (= conserve FALSE) (begin
154+
;(gimp-message "line154")
155+
;(gimp-display-new image)
156+
;(gimp-displays-flush)
157+
;(quit)
158+
(gimp-progress-update 0.4)
159+
160+
(set! calcoffset (+ 0 snowupdown))
161+
(gimp-layer-set-offsets snowshadow-layer 0 calcoffset )
162+
(gimp-layer-set-offsets snowtop-layer 0 calcoffset)
163+
;(gimp-layer-set-offsets snow-layer 0 calcoffset)
164+
165+
;(gimp-message "line162")
166+
;(gimp-display-new image)
167+
;(gimp-displays-flush)
168+
;(quit)
169+
(gimp-progress-update 0.8)
170+
171+
;;;;finish the script
172+
(if (= conserve FALSE)
173+
(begin
118174
(gimp-image-remove-layer image snow-layer)
119175
(set! layer (car (gimp-image-merge-down image snowtop-layer EXPAND-AS-NECESSARY)))
120176
(set! layer (car (gimp-image-merge-down image snowshadow-layer EXPAND-AS-NECESSARY)))
@@ -123,6 +179,7 @@
123179
(cond ((= ver 2.8) (gimp-item-set-name layer (string-append layer-name "\nSnow")))
124180
(else (gimp-drawable-set-name layer (string-append layer-name "\nSnow")))
125181
) ;endcond
182+
(gimp-progress-update 1.0)
126183

127184
(gimp-displays-flush)
128185
(gimp-image-undo-group-end image)
@@ -140,7 +197,8 @@
140197
"RGB*"
141198
SF-IMAGE "image" 0
142199
SF-DRAWABLE "drawable" 0
143-
SF-ADJUSTMENT "Snow Depth" '(10 0 50 1 10 0 0)
200+
SF-ADJUSTMENT "Snow Depth" '(10 0 70 1 10 0 0)
201+
SF-ADJUSTMENT "Snow Depth updown adjustment" '(2 -50 50 1 10 0 0)
144202
SF-TOGGLE "Keep the Layers" FALSE
145203
)
146204

@@ -159,6 +217,8 @@
159217
gradient-type
160218
reverse
161219
blendir
220+
thinfontadjust
221+
additionaladjustment
162222
conserve
163223
)
164224
(let* (
@@ -182,7 +242,13 @@
182242
(x2 0)
183243
(y2 0)
184244
(ver 2.8)
245+
(calcoffset 0)
246+
(adjustoffset 0)
247+
(shrinkamount 3)
185248
)
249+
250+
;(gimp-message "snow cover logo start")
251+
(gimp-progress-update 0.05)
186252
(cond ((not (defined? 'gimp-image-get-item-position)) (set! ver 2.6))) ;define the gimp version
187253

188254
(gimp-context-push)
@@ -205,7 +271,8 @@
205271
;;;;start of script;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
206272
;;;;save the selection
207273
(cond ((= ver 2.8) (gimp-image-select-item image 2 text-layer))
208-
(else (gimp-selection-layer-alpha text-layer)))
274+
(else (gimp-selection-layer-alpha text-layer)))
275+
209276
(set! text-selection (car (gimp-selection-save image))) ;(gimp-selection-load text-selection)
210277
(gimp-selection-none image)
211278

@@ -214,8 +281,25 @@
214281
(include-layer image innermap text-layer 1) ;stack 0=above 1=below
215282
(gimp-context-set-foreground '(255 255 255))
216283
(gimp-edit-fill innermap FILL-FOREGROUND)
284+
285+
; added by karlhof26
286+
;(gimp-message "line222")
287+
(gimp-progress-update 0.4)
288+
; calc offsets to allow fine tuning
289+
;(set! calcoffset (+ (- 0 depth) adjustoffset))
290+
; adjust the exact position by a few pixels; positive for down;neg for up
291+
;(gimp-layer-set-offsets innermap 0 snowupdown)
292+
217293
(gimp-selection-load text-selection)
218-
(gimp-selection-shrink image 3)
294+
(if (= thinfontadjust TRUE)
295+
(begin
296+
;no shrink; shrink is off
297+
)
298+
(begin
299+
;default for normal and fat fonts
300+
(gimp-selection-shrink image shrinkamount)
301+
)
302+
)
219303
(gimp-context-set-foreground '(0 0 0))
220304
(gimp-edit-fill innermap FILL-FOREGROUND)
221305
(gimp-selection-none image)
@@ -241,26 +325,44 @@
241325
1)
242326

243327
(gimp-selection-load text-selection)
244-
(gimp-selection-shrink image 2)
328+
(if (= thinfontadjust TRUE)
329+
(begin
330+
; it is off
331+
)
332+
(begin
333+
(gimp-selection-shrink image (- shrinkamount 1))
334+
)
335+
)
336+
245337
(set! masktext (car (gimp-layer-create-mask text-layer ADD-MASK-SELECTION)))
246338
(gimp-layer-add-mask text-layer masktext)
247339
(gimp-selection-none image)
248340
(plug-in-gauss-rle2 1 image masktext 1 1)
249341
(gimp-layer-remove-mask text-layer MASK-APPLY)
342+
343+
(gimp-progress-update 0.7)
344+
;(gimp-message "line260")
345+
;(gimp-display-new image)
346+
;(gimp-displays-flush)
347+
;(quit);
348+
250349
(gimp-image-remove-layer image innermap)
251350
(gimp-image-remove-channel image text-selection)
252351

253352

254353
;;;;create the background layer
255354
;;;;create the background layer
256355
(cond ((not (= bkg-type 0))
257-
(set! bkg-layer (car (gimp-layer-new image width height RGBA-IMAGE "Background" 100 LAYER-MODE-NORMAL)))
258-
(include-layer image bkg-layer text-layer 1) ;stack 0=above 1=below
356+
(set! bkg-layer (car (gimp-layer-new image width height RGBA-IMAGE "Background" 100 LAYER-MODE-NORMAL)))
357+
(include-layer image bkg-layer text-layer 1) ;stack 0=above 1=below
358+
(gimp-progress-update 0.75)
359+
;(gimp-message "line 274 bkg not 0")
259360
)
260361
) ;endcond
261362
(gimp-context-set-pattern pattern)
262363
(gimp-context-set-background bkg-color)
263364
(gimp-context-set-gradient gradient)
365+
264366
(if (or (= bkg-type 3) (= bkg-type 4))
265367
(begin
266368
(gimp-context-set-foreground active-fg)
@@ -289,14 +391,30 @@
289391
(gimp-edit-blend bkg-layer BLEND-CUSTOM LAYER-MODE-NORMAL gradient-type 100 0 REPEAT-NONE reverse FALSE 3 0.2 TRUE x1 y1 x2 y2)
290392
)
291393
) ;endif
292-
293-
294-
394+
395+
(gimp-progress-update 0.8)
396+
;(gimp-message "line351")
397+
;(gimp-display-new image)
398+
;(gimp-displays-flush)
399+
;(quit);
400+
;(gimp-message "line314 off to alpha")
401+
402+
(if (> depth 26)
403+
(begin
404+
;(gimp-message "setadjust for large snow depths")
405+
(set! adjustoffset (+ additionaladjustment (round (* 0.52 depth)))) ; worked at 0.60
406+
)
407+
(begin
408+
;(gimp-message "setadjust for small snow depths")
409+
(set! adjustoffset additionaladjustment)
410+
)
411+
)
295412
;;;;resize the text-layer
296413
(gimp-image-set-active-layer image text-layer)
297414
(script-fu-snow-cover-alpha image
298415
text-layer
299416
depth
417+
adjustoffset
300418
conserve)
301419
; (gimp-layer-resize-to-image-size text-layer)
302420

@@ -313,25 +431,28 @@
313431
)
314432
)
315433
(script-fu-register "script-fu-snow-cover-logo"
316-
"Snow Cover Logo..."
317-
"Create a Logo covered in a snow drift \nfile: Snow Cover.scm"
318-
"Graechan"
319-
"Graechan - http://gimpchat.com"
320-
"Dec 2013"
321-
""
322-
SF-TEXT "Text" "SEASONS\nGREETINGS"
323-
SF-COLOR "Text color" '(255 0 0)
324-
SF-FONT "Font" "Arial Bold"
325-
SF-ADJUSTMENT "Font size (pixels)" '(250 6 500 1 1 0 1)
326-
SF-ADJUSTMENT "Snow Depth" '(10 0 50 1 10 0 0)
327-
SF-OPTION "Background Type" '("None" "Color" "Pattern" "Gradient" "Active Gradient")
328-
SF-PATTERN "Pattern" "Pink Marble"
329-
SF-COLOR "Background color" "Blue"
330-
SF-GRADIENT "Background Gradient" "Abstract 3"
331-
SF-ENUM "Gradient Fill Mode" '("GradientType" "gradient-linear")
332-
SF-TOGGLE "Reverse the Gradient" FALSE
333-
SF-OPTION "Blend Direction" list-blend-dir
334-
SF-TOGGLE "Keep the Layers" FALSE
434+
"Snow Cover Logo..."
435+
"Create a Logo covered in a snow drift. Turn thin font adjustment on for very thin fonts. Use addtionaladjustment to lower snow onto letters. \nfile: Snow Cover.scm"
436+
"Graechan"
437+
"Graechan - http://gimpchat.com"
438+
"Dec 2013"
439+
""
440+
SF-TEXT "Text" "SEASONS\nGREETINGS"
441+
SF-COLOR "Text color" '(255 0 0)
442+
SF-FONT "Font" "Arial Bold"
443+
SF-ADJUSTMENT "Font size (pixels)" '(250 6 500 1 1 0 1)
444+
SF-ADJUSTMENT "Snow Depth" '(10 0 50 1 10 0 0)
445+
SF-OPTION "Background Type" '("None" "Color" "Pattern" "Gradient" "Active Gradient")
446+
SF-PATTERN "Pattern" "Pink Marble"
447+
SF-COLOR "Background color" "Blue"
448+
SF-GRADIENT "Background Gradient" "Abstract 3"
449+
SF-ENUM "Gradient Fill Mode" '("GradientType" "gradient-linear")
450+
SF-TOGGLE "Reverse the Gradient" FALSE
451+
SF-OPTION "Blend Direction" list-blend-dir
452+
SF-TOGGLE "Thin font adjustment " FALSE
453+
SF-ADJUSTMENT "Additional adjustment" '(1 -30 70 1 10 0 0)
454+
SF-TOGGLE "Keep the Layers" FALSE
455+
335456
)
336457

337458
(script-fu-menu-register "script-fu-snow-cover-logo" "<Image>/Script-Fu/Logos" )

0 commit comments

Comments
 (0)