-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path210_RandomFontText.scm
788 lines (688 loc) · 34.3 KB
/
210_RandomFontText.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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
; Random Font Text rel 5.2
; Created by Graechan and GnuTux
; You will need to install GMIC to run the cube option in this Scipt
; GMIC can be downloaded from http://sourceforge.net/projects/gmic/files/
; Comments directed to http://gimpchat.com or http://gimpscripts.com
;
; License: GPLv3
; 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.
;
; To view a copy of the GNU General Public License
; visit: http://www.gnu.org/licenses/gpl.html
;
;
; ------------
;| Change Log |
; ------------
; Rel 0.01 - Initial Release
; Rel 0.02 - Added Palette selection or (random RGB color choice) for color Choice; option for rotation threshold, option to bumbmap letters
; Rel 0.03 - Added 'Random color from random palette' to color choices, moved cornercurl back to toggle
; Added bumpmap, chisel and 'inner shadow' to 'Text Effects'
; Added the options to lock the font and color
; Rel 0.04 - Added Text output options
; Rel 0.05 - Added Text 0n cubes option{THIS OPTION REQUIES GMIC}, option to square the text layers and option to add an individual Bkg color to layers
; Rel 0.5.1 - Improved rendering
; Rel 0.5.2 - Improved GUI, and added font name to layers if Text Output Options = Each Character On Separate Layer
; slight update for gimp 2.10 and gimp_gimp_qt - rich - 31 July 2021
; Rel 0.5.4 - now works with 4 colors palette without errors.
;
;;;; define default pattern
(define default-pattern
(let* (
(pat FALSE)
(default-patternId " ")
)
(map (lambda (x) (if (string=? x "paper_4") (set! pat TRUE))) (cadr (gimp-patterns-get-list "")))
(cond ((= pat TRUE)
(set! default-patternId "paper_4"))
(else (set! default-patternId "Crinkled Paper"))))
(list default-patternId)
) ;end defaut-pattern proceedure
;
; Include layer Procedure
(define (include-layer image newlayer oldlayer stack) ;stack 0=above 1=below
(cond ((defined? 'gimp-image-get-item-position) ;test for 2.8 compatability
(gimp-image-insert-layer image newlayer (car (gimp-item-get-parent oldlayer))
(+ (car (gimp-image-get-item-position image oldlayer)) stack)) ;For GIMP 2.8
)
(else
(gimp-image-add-layer image newlayer (+ (car (gimp-image-get-layer-position image oldlayer)) stack)) ;For GIMP 2.6
)
) ;end cond
) ;end include layer procedure
;
(define (script-fu-random-font-text
text ;text input
font-size ;font size
font-color ;font color options
palette ;selected palette
locked-color ;locked color
lower ;rgb lower limit
upper ;rgb upper limit
font-filter ;font filter
font-in ;locked font
rot-let ;letter rotation
text-output ;text output options
text-effect ;text effect (0=none 1=bump 2=chisel 3=stroke 4= Inner shadow)
effect-color ;sroke or inner shadow color
stroke-radius ;text stroke Radius
effect-blur ;inner shadow blur
layerOutline ;layer outline
brush-size ;outline brush size
lyr-bkg ;apply color to the layer background
square ;square the text layers
lcurl ;layer curl
cube ;text in cubes
bkg-type ;bkg type (0=none 1=pattern 2=color 3=transparency)
bkg-pattern ;background pattern
bkg-color ;background color
)
(let* (
(width 3000) ;width flag (set to initial image width)
(height 3000) ;height flag (set to initial image height)
(offx (/ font-size 4)) ;X offset flag
(offy (/ font-size 4)) ;Y offset flag
(image (car (gimp-image-new width height RGB))) ;image
(font (if (> (string-length font-in) 0) font-in (car (gimp-context-get-font))))
(bkg-layer 0)
(text-layer 0)
(activeLayer 0)
(effect-layer 0)
(effect-channel 0)
(effect-mask 0)
(ver 2.8) ;gimp version flag
(letterList ())
(letter 0)
(random-font 0) ;font flag
(random-color 0) ;color flag
(random-rotation 0) ;rotation flag
(center-x 0) ;layer center X flag
(center-y 0) ;layer center Y flag
(f1 FALSE) ;f1 flag space detect
(f2 FALSE) ;f2 flag line detect
(f3 FALSE) ;f3 flag layerOutline brush detect
(f4 FALSE) ;f4 flag channel detect
(f5 FALSE) ;f5 flag textOutline brush detect
(r 0) ;(r)gb random
(g 0) ;r(g)b random
(b 0) ;rg(b) random
(ffilter 0) ;Font Filter
(name "") ;name flag
(flatten-color 0) ;flatten color flag
(size 0) ;size flag
(n 1) ;line number flag
)
(cond ((not (defined? 'gimp-image-get-item-position)) (set! ver 2.6))) ;define the gimp version
(gimp-context-push)
(gimp-context-set-paint-method "gimp-paintbrush")
(if (= ver 2.8) (gimp-context-set-dynamics "Dynamics Off"))
(gimp-context-set-foreground '(0 0 0))
(gimp-context-set-background '(255 255 255))
(gimp-context-set-antialias TRUE)
;;;;begin the script
(set! *seed* (car (gettimeofday))) ; Random Number Seed From Clock (*seed* is global)
(random-next) ; Next Random Number Using Seed
(if (= font-color 1) ;select pallete at random
(begin
(set! palette (vector-ref (list->vector (cadr (gimp-palettes-get-list "")))
(rand (car (gimp-palettes-get-list ""))))) ;get random palette
(gimp-palettes-set-palette palette) ; set random palette
)
)
(set! letterList (map (lambda (x) (make-string 1 x)) (string->list text))) ;create the list of letters
(while (not (null? letterList))
(set! letter (car letterList)) ;aquire the next letter
(if (string=? letter " ") (begin ;check if letter is valid (not space)
(set! letter "-") ;change the letter to valid text
(set! f1 TRUE) ;set the f1 flag
)) ;endif
(if (string=? letter "\n") (begin ;check if letter is valid (not \n)
(set! letter "-") ;change the letter to valid text
(set! f2 TRUE) ;set the f2 flag
)) ;endif
(if (= font-filter 0) ;Font Filter Options
(begin
(set! ffilter "")
))
(if (= font-filter 1)
(begin
(set! ffilter "Bold")
))
(if (= font-filter 2)
(begin
(set! ffilter "Italic")
))
(if (< font-filter 3)
(begin
(set! random-font (list-ref (cadr (gimp-fonts-get-list ffilter))
(round (random (car (gimp-fonts-get-list ffilter)))))) ;select random font
))
(if (= font-filter 3)
(set! random-font font)
)
; Color Options
;
(if (= font-color 0)
(begin
(set! random-color (car (gimp-palette-entry-get-color palette
(- (random (car (gimp-palette-get-colors palette))) 1)
))) ;random color from palette
)
)
(if (= font-color 1)
(begin
(set! random-color (car (gimp-palette-entry-get-color palette
(- (random (car (gimp-palette-get-colors palette))) 1)
))) ;random color from palette
)
)
(if (= font-color 2)
(begin
(if (> lower upper) ;make sure lower is >= upper
(set! lower (- upper 1))
)
(set! r (+ (rand (- upper lower)) lower)) ;caculate random number range
(set! g (+ (rand (- upper lower)) lower))
(set! b (+ (rand (- upper lower)) lower))
(set! random-color (list r g b)) ;select random color
)
)
(if (= font-color 3)
(begin
(set! random-color locked-color)
)
)
(gimp-context-set-foreground random-color) ;set foreground color
(set! text-layer (car (gimp-text-fontname ;create a new text layer
image ;image
-1 ;drawable { The affected drawable: (-1 for a new text layer)}
0 ;x The x coordinate for the left of the text bounding box
0 ;y The y coordinate for the top of the text bounding box
letter ;text The text to generate (in UTF-8 encoding)(symbol->string letter) ;
0 ;border The size of the border (border >= -1)
TRUE ;antialias Antialiasing (TRUE or FALSE)
font-size ;size The size of text in either pixels or points (size >= 0)
PIXELS ;size-type The units of specified size { PIXELS (0), POINTS (1) }
random-font))) ;fontname The name of the font
(set! activeLayer (car (gimp-image-get-active-layer image))) ;assign the new layer as "activeLayer"
;;;;------------------------------------------------------------------------------------------------------create the text effects
(if (or (= text-effect 1) (= text-effect 3) (= text-effect 4))
(begin
(gimp-selection-layer-alpha activeLayer)
(set! effect-channel (car (gimp-selection-save image))) ;(gimp-selection-load effect-channel)
(gimp-selection-none image)
(set! f4 TRUE)
)) ;endif
(if (= text-effect 1) (begin ;-------------------------------------------------------------------------------------------------------bumpmap
(plug-in-bump-map RUN-NONINTERACTIVE image activeLayer effect-channel 135 45 5 0 0 0 0 TRUE FALSE 0) ;bumpmap the activeLayer
)) ;endif
(if (= text-effect 2) (begin ;-------------------------------------------------------------------------------------------------------chisel
(rft-chisel image activeLayer 20 5 0 0 135 30 20 0 0 0 FALSE)
(set! activeLayer (car (gimp-image-merge-down image (car (gimp-image-get-active-layer image)) EXPAND-AS-NECESSARY)))
)) ;endif
(if (= text-effect 3) (begin ;------------------------------------------------------------------------------------------------------color stroke
(gimp-selection-load effect-channel)
(set! effect-layer (car (gimp-layer-copy activeLayer TRUE))) ;create and add effect-layer
(include-layer image effect-layer activeLayer 0) ;stack 0=above 1=below
(gimp-context-set-foreground effect-color) ;set the stroke color
(gimp-edit-fill effect-layer FILL-FOREGROUND) ;fill background with text color
(gimp-selection-shrink image stroke-radius)
(gimp-edit-clear effect-layer)
(gimp-selection-none image)
(set! activeLayer (car (gimp-image-merge-down image effect-layer EXPAND-AS-NECESSARY)))
(gimp-context-set-foreground random-color) ;set foreground color
)) ;endif
(if (= text-effect 4) (begin ;----------------------------------------------------------------------------------------------Inner shadow
(set! effect-layer (car (gimp-layer-copy activeLayer TRUE)))
(include-layer image effect-layer activeLayer 0) ;stack 0=above 1=below
(gimp-context-set-foreground effect-color)
(gimp-selection-load effect-channel)
(gimp-edit-fill effect-layer FILL-FOREGROUND)
(gimp-selection-invert image)
(set! effect-mask (car (gimp-layer-create-mask effect-layer ADD-MASK-SELECTION)))
(gimp-layer-add-mask effect-layer effect-mask)
(gimp-selection-none image)
(plug-in-gauss-rle2 RUN-NONINTERACTIVE image effect-mask effect-blur effect-blur)
(set! activeLayer (car (gimp-image-merge-down image effect-layer EXPAND-AS-NECESSARY)))
(gimp-context-set-foreground random-color) ;reset foreground color
)) ;endif
(if (= f4 TRUE) (gimp-image-remove-channel image effect-channel)) ;remove the channel
(if (and (= cube FALSE) (= square FALSE))
(begin
(if (= lyr-bkg TRUE)
(begin
(set! bkg-layer (car (gimp-layer-copy activeLayer TRUE))) ;create and add bkg-layer
(include-layer image bkg-layer activeLayer 1) ;stack 0=above 1=below
(gimp-drawable-fill bkg-layer FILL-FOREGROUND) ;fill background with text color
(gimp-invert bkg-layer) ;invert background color
(set! activeLayer (car (gimp-image-merge-down image activeLayer EXPAND-AS-NECESSARY)))
)
) ;endif
)
) ;endif
;;;;----------------------------------------------------------------------------------------------------------------resize for cube text
(if (or (= cube TRUE) (= square TRUE))
(begin
(set! size (max (car (gimp-drawable-width activeLayer)) (car (gimp-drawable-height activeLayer)))) ;set the size flag
(gimp-layer-resize activeLayer
size ;set the new width
size ;set the new height
(/ (- size (car (gimp-drawable-width activeLayer))) 2) ;set xoff
(/ (- size (car (gimp-drawable-height activeLayer))) 2)) ;set yoff
(if (or (= cube TRUE) (= lyr-bkg TRUE))
(begin
(set! bkg-layer (car (gimp-layer-copy activeLayer TRUE))) ;create and add bkg-layer
(include-layer image bkg-layer activeLayer 1) ;stack 0=above 1=below
(gimp-drawable-fill bkg-layer FILL-FOREGROUND) ;fill background with text color
(gimp-invert bkg-layer) ;invert background color
(set! activeLayer (car (gimp-image-merge-down image activeLayer EXPAND-AS-NECESSARY)))
)
) ;endif
)
) ;endif
(gimp-layer-set-offsets activeLayer offx offy) ;offset the activeLayer
(set! center-x (+ offx (/ (car (gimp-drawable-width activeLayer)) 2))) ;get the x-center of layer
(set! center-y (+ offy (/ (car (gimp-drawable-height activeLayer)) 2))) ;get the y-center of layer
;outline and pagecurl the active layer here----------------------------------------------------------------------------------------------------
(if (= layerOutline TRUE) ;create layer ouline
(begin
(gimp-rect-select image ;select the activeLayer
(car (gimp-drawable-offsets activeLayer))
(cadr (gimp-drawable-offsets activeLayer))
(car (gimp-drawable-width activeLayer))
(car (gimp-drawable-height activeLayer))
CHANNEL-OP-REPLACE ;operation
FALSE ;feather
10) ;feather radious
(set! bkg-layer (car (gimp-layer-copy activeLayer TRUE))) ;create and add bkg-layer
(include-layer image bkg-layer activeLayer 0) ;stack 0=above 1=below
(gimp-context-set-foreground random-color)
(gimp-drawable-fill bkg-layer FILL-FOREGROUND) ;fill background with text color
(gimp-selection-shrink image brush-size)
(gimp-edit-clear bkg-layer)
(gimp-selection-none image)
(set! activeLayer (car (gimp-image-merge-down image bkg-layer EXPAND-AS-NECESSARY)))
)
) ;endif
(if (= lcurl TRUE) ;create a layer corner curl
(begin
(gimp-rect-select image ;select the 'lower right' of activeLayer
center-x
center-y
(car (gimp-drawable-width activeLayer))
(car (gimp-drawable-height activeLayer))
CHANNEL-OP-REPLACE ;operation
FALSE ;feather
10) ;feather radious
(plug-in-pagecurl 1 image activeLayer 0 1 1 1) ;run Pagecurl plugin
(set! activeLayer (car (gimp-image-merge-down image (car (gimp-image-get-active-layer image)) EXPAND-AS-NECESSARY)))
(gimp-selection-none image) ;remove the selection
(if (= cube TRUE)
(begin
(set! bkg-layer (car (gimp-layer-copy activeLayer TRUE))) ;create and add bkg-layer
(include-layer image bkg-layer activeLayer 1) ;stack 0=above 1=below
(gimp-context-set-pattern "Wood #2") ;set the pattern
(gimp-drawable-fill bkg-layer FILL-PATTERN) ;fill background with pattern
(set! activeLayer (car (gimp-image-merge-down image activeLayer EXPAND-AS-NECESSARY)))
)
) ;endif
)
) ;endif
(if (defined? 'plug-in-gmic-qt)
(begin
(if (= cube TRUE)
(begin
; *******************************************start 3d image object
;; Matching variables
(set! activeLayer (car (gimp-image-get-active-layer image))) ;set the activeLayer
(set! width (car (gimp-drawable-width activeLayer))) ;set the width
(set! height (car (gimp-drawable-height activeLayer))) ;set the height
;; Render Imageobject3d using G'MIC.
(plug-in-gmic-qt 1 image activeLayer 1 0
(string-append
"-v - " ; To have a silent output. Remove it to display errors from the G'MIC interpreter on stderr.
"fx_imageobject3d 1,"
(number->string width) ","
(number->string height) ",0.56,57,41,21,45,0,0,-100,0,0,4,1"
)
)
; *******************************************end 3d image object
(set! activeLayer (car (gimp-image-get-active-layer image))) ;assign the new layer as "activeLayer"
)
) ;endif
)
) ;endif
(if (= text-output 0)
(begin
(gimp-drawable-set-name activeLayer (string-append letter "\n" random-font)))
(begin
(gimp-drawable-set-name activeLayer letter) ;restore the layers correct name
)
)
(gimp-hue-saturation activeLayer 0 0 -70 100)
(if (> rot-let 0)
(begin
(set! random-rotation (/ (- (random rot-let) (/ rot-let 2)) 100)) ;set the rotation threshold angle
(gimp-drawable-transform-rotate-default activeLayer random-rotation TRUE center-x center-y TRUE 0)
)
) ;endif
(gimp-layer-set-offsets activeLayer offx offy) ; offset the activeLayer
(set! offx (+ offx (car (gimp-drawable-width activeLayer)))) ;set the x offset
(if (= f2 TRUE) ;check if f2 flag has been set
(begin
(gimp-image-remove-layer image activeLayer) ;remove the current layer
(gimp-image-resize-to-layers image) ;set the image size
(set! offx 0) ;set the offx flag
(set! offy (car (gimp-image-height image))) ;set the offy flag
)
) ;endif
(if (= f1 TRUE) ;check if f1 flag has been set
(begin
(gimp-image-remove-layer image activeLayer) ;remove the current layer
)
) ;endif
(if (= text-output 1) ;--------------------------------individual words
(begin
(if (and (= f1 FALSE) (= f2 FALSE))
(begin
(set! name (string-append name (car (gimp-drawable-get-name activeLayer))))
)
)
)
)
(if (= text-output 2) ;---------------------------------individual lines
(begin
(if (and (= f1 FALSE) (= f2 FALSE))
(begin
(set! name (string-append name (car (gimp-drawable-get-name activeLayer))))
)
)
(if (and (= f1 TRUE) (= f2 FALSE))
(begin
(set! name (string-append name " "))
)
)
)
)
(gimp-image-resize image 3000 3000 0 0) ;resize the image for next line
;;;;----------------------------------------------------------------------------------------------------set text output options here
(if (= text-output 1) ;--------------------------------individual words
(begin
(if (or (= f1 TRUE) (= f2 TRUE))
(begin
(set! text-layer (car (gimp-image-merge-visible-layers image EXPAND-AS-NECESSARY))) ;merge the text layers
(gimp-drawable-set-name text-layer name)
(set! name "")
(gimp-drawable-set-visible text-layer FALSE)
)
)
)
)
(if (= text-output 2) ;---------------------------------individual lines
(begin
(if (= f2 TRUE)
(begin
(set! text-layer (car (gimp-image-merge-visible-layers image EXPAND-AS-NECESSARY))) ;merge the text layers
(gimp-drawable-set-name text-layer (string-append "Line" (number->string n) "\n" name))
(set! name "")
(gimp-drawable-set-visible text-layer FALSE)
(set! n (+ n 1))
)
)
)
)
(set! f1 FALSE) ;reset the f1 flag
(set! f2 FALSE) ;reset the f2 flag
(set! letterList (cdr letterList))
) ;endwhile
(if (= text-output 1)
(begin
(set! text-layer (car (gimp-image-merge-visible-layers image EXPAND-AS-NECESSARY))) ;merge the text layers
(gimp-drawable-set-name text-layer name)
(map (lambda (x) (gimp-drawable-set-visible x TRUE)) (vector->list (cadr (gimp-image-get-layers image))))
)
)
(if (= text-output 2) ;---------------------------------individual lines
(begin
(set! text-layer (car (gimp-image-merge-visible-layers image EXPAND-AS-NECESSARY))) ;merge the text layers
(gimp-drawable-set-name text-layer (string-append "Line" (number->string n) "\n" name))
(map (lambda (x) (gimp-drawable-set-visible x TRUE)) (vector->list (cadr (gimp-image-get-layers image))))
)
)
(if (= text-output 3)
(begin
(set! text-layer (car (gimp-image-merge-visible-layers image EXPAND-AS-NECESSARY))) ;merge the text layers
(gimp-drawable-set-name text-layer text) ;name the merged text-layers
)
)
(gimp-image-resize-to-layers image) ;set the image size
(set! width (car (gimp-image-width image))) ;set the width
(set! height (car (gimp-image-height image))) ;set the height
(script-fu-reverse-layers image (car (gimp-image-get-active-layer image))) ;reverse layer order
(if (> bkg-type 0) (begin
(set! bkg-layer (car (gimp-layer-new image width height RGBA-IMAGE "Background" 100 LAYER-MODE-NORMAL-LEGACY))) ;create and add the bkg-layer
(cond ((= ver 2.8) ;insert or add the new bkg layer
(gimp-image-insert-layer image bkg-layer 0 0)) ;new layer 2.8
(else (gimp-image-add-layer image bkg-layer 0)) ;new layer 2.6
) ;endcond
(gimp-image-lower-layer-to-bottom image bkg-layer) ;lower bkg-layer to bottom of stack
)) ;endif
(gimp-context-set-pattern bkg-pattern) ;set the active pattern
(gimp-context-set-background bkg-color)
(if (= bkg-type 1) (gimp-drawable-fill bkg-layer FILL-PATTERN)) ;fill the bkg-layer with pattern
(if (= bkg-type 2) (gimp-drawable-fill bkg-layer FILL-BACKGROUND)) ;fill the bkg-layer with color
(if (= font-color 1) (begin
(let ((handler (car (gimp-message-get-handler))))
(gimp-message-set-handler 0) ;{ MESSAGE-BOX (0), CONSOLE (1), ERROR-CONSOLE (2) }
(gimp-message (string-append "Random palette used is" " " palette))
(gimp-message-set-handler handler))
)) ;endif
;;;;finish the script
(gimp-display-new image)
(gimp-displays-flush)
(gimp-context-pop)
)
)
(script-fu-register "script-fu-random-font-text"
"Random Font Text..."
"Creates text with each letter having a different font. Options include user configurable font size, choice of filter for random font selection,
background pattern, letter effects, random rotation of each letter, letter outline, curl and layer merging. "
"Graechan & GnuTux"
"Graechan - http://gimpchat.com"
"July 2014"
""
SF-TEXT "Text" "Random\nFont Text"
SF-ADJUSTMENT "Font Size (pixels)" '(200 6 500 1 1 0 1)
SF-OPTION "Font Color" '("Random From Selected Color Palette" "Random From Random Color Pallete" "Random RGB Color From Range" "Locked Color")
SF-PALETTE "Color Palette" "Named Colors"
SF-COLOR "Locked Color" '(0 255 0)
SF-ADJUSTMENT "RGB Color Range Start" '(0 0 255 1 5 0 0)
SF-ADJUSTMENT "RGB Color Range End" '(255 1 255 1 5 0 0)
SF-OPTION "Font Filter" '("All Fonts" "Bold Fonts Only" "Italic Fonts Only" "Use Locked Font")
SF-FONT "Locked Font" "Serif Bold"
SF-ADJUSTMENT "Font Rotation 0=Off" '(0 0 180 1 10 0 0)
SF-OPTION "Text Output Options" '("Each Character On Separate Layer" "Each Word On Separate Layer" "Each Line On Separate Layer" "All Text On Single Layer")
SF-OPTION "Text Effect" '("None" "Bump" "Chisel" "Stroke" "Inner Shadow")
SF-COLOR "Stroke/Shadow Color" "Black"
SF-ADJUSTMENT "Stroke Width" '(1 1 15 1 1 0 0)
SF-ADJUSTMENT "Shadow Blur Radius" '(20 0 50 1 5 0 0)
SF-TOGGLE "Text Border Outline" FALSE
SF-ADJUSTMENT "Border Outline Width" '(4 1 10 1 1 0 0)
SF-TOGGLE "Color Each Character's Background" FALSE
SF-TOGGLE "Square Layers" FALSE
SF-TOGGLE "Corner Curl" FALSE
SF-TOGGLE "Cubes {Requires GMIC}" FALSE
SF-OPTION "Image Background" '("None" "Pattern" "Color" "Transparency")
SF-PATTERN "Image Background Pattern" default-pattern
SF-COLOR "Image Background Color" "White"
)
(script-fu-menu-register "script-fu-random-font-text" "<Image>/Script-Fu/Logos/")
;--------------------------------------------------------------------------------------------------------
(define (rft-chisel img inLayer inWidth inSoften inCurve inPow inAizmuth inElevation inDepth inMode inLocation inBlur inKeepBump)
(let*
(
(varNoSelection (car (gimp-selection-is-empty img)))
(inPow (- 0 inPow))
(varSavedSelection 0)
(varBlurredSelection 0)
(varBumpmapLayer)
(varBevelLayer)
(varLoopCounter 1)
(varFillValue)
(varNumBytes 256)
(varAdjCurve (cons-array varNumBytes 'byte))
(varLayerName (car (gimp-drawable-get-name inLayer)))
)
; it begins here
(gimp-context-push)
(gimp-image-undo-group-start img)
;save selection or select all if no selection
(if (= varNoSelection TRUE)
(if (= (car (gimp-drawable-has-alpha inLayer)) TRUE) ;check for alpha
(gimp-selection-layer-alpha inLayer) ; transfer the alpha to selection
(gimp-selection-all img) ;else select the whole image
)
)
(set! varSavedSelection (car (gimp-selection-save img)))
(set! varBumpmapLayer (car (gimp-layer-new-from-drawable inLayer img)))
(gimp-drawable-set-name varBumpmapLayer (string-append varLayerName " bumpmap"))
(gimp-image-add-layer img varBumpmapLayer -1)
(if (= inLocation 1) ;if outside, enlarge the layer canvas
(gimp-layer-resize varBumpmapLayer (+ (car (gimp-drawable-width inLayer)) (* 2 inWidth))
(+ (car (gimp-drawable-height inLayer)) (* 2 inWidth))
inWidth
inWidth)
)
;blur selection for soft chisel
(gimp-selection-feather img inSoften)
(set! varBlurredSelection (car (gimp-selection-save img)))
;when shrinking check selection size and reset inWidth if necessary
(when (= inLocation 0)
(set! varLoopCounter inWidth)
(gimp-selection-shrink img varLoopCounter)
(while (= (car (gimp-selection-is-empty img)) TRUE)
(set! varLoopCounter (- varLoopCounter 1))
(gimp-selection-load varBlurredSelection)
(gimp-selection-shrink img varLoopCounter)
;(gimp-progress-set-text "Chiseling...")
;(gimp-progress-pulse)
)
;(gimp-progress-set-text "")
(set! inWidth (min inWidth varLoopCounter))
(gimp-selection-load varBlurredSelection)
)
; create bevel in bumpmap layer black to white
(gimp-context-set-foreground '(0 0 0))
(gimp-drawable-fill varBumpmapLayer FILL-FOREGROUND)
(set! varLoopCounter 1)
(while (<= varLoopCounter inWidth)
;inCurve of 0 will be flat, inCurve of 1 is a quarter round, inCurve of -1 is a quarter round fillet
(set! varFillValue (* (pow (+ (* (- (sin (* (/ varLoopCounter inWidth) (tan 1))) (/ varLoopCounter inWidth)) inCurve) (/ varLoopCounter inWidth)) (pow 2 inPow)) 255))
;avoid distortion
(gimp-selection-load varBlurredSelection)
(if (= inLocation 0)
(gimp-selection-shrink img (- varLoopCounter 1)) ;inside
(gimp-selection-grow img (- inWidth (- varLoopCounter 1))) ;outside
)
(gimp-context-set-foreground (list varFillValue varFillValue varFillValue)) ;shade of grey
(if (= (car (gimp-selection-is-empty img)) FALSE)
(gimp-edit-fill varBumpmapLayer FILL-FOREGROUND)
(gimp-edit-fill varBumpmapLayer FILL-FOREGROUND) ; second time to blend better
(set! varLoopCounter (+ inWidth 1))
)
(set! varLoopCounter (+ varLoopCounter 1))
)
;finish up with white
(gimp-context-set-foreground (list 255 255 255)) ;white
(gimp-selection-load varBlurredSelection)
(if (= inLocation 0)
(gimp-selection-shrink img inWidth) ;inside
)
(if (= (car (gimp-selection-is-empty img)) FALSE)
(gimp-edit-fill varBumpmapLayer FILL-FOREGROUND)
(gimp-edit-fill varBumpmapLayer FILL-FOREGROUND) ; second time to blend better
)
(gimp-selection-none img)
;make bevel from bumpmap
(set! varBevelLayer (car (gimp-layer-new-from-drawable inLayer img)))
(gimp-drawable-set-name varBevelLayer (string-append varLayerName " bevel"))
(gimp-image-add-layer img varBevelLayer -1)
(if (= inLocation 1) ;if outside, enlarge the layer canvas
(gimp-layer-resize varBevelLayer (+ (car (gimp-drawable-width inLayer)) (* 2 inWidth))
(+ (car (gimp-drawable-height inLayer)) (* 2 inWidth))
inWidth
inWidth)
)
(gimp-context-set-foreground '(127 127 127))
(gimp-drawable-fill varBevelLayer FILL-FOREGROUND)
(plug-in-bump-map RUN-NONINTERACTIVE img varBevelLayer varBumpmapLayer inAizmuth inElevation inDepth 0 0 0 0
TRUE (cond ((= inMode 0) FALSE) ((= inMode 1) TRUE)) 1)
(gimp-layer-set-mode varBevelLayer LAYER-MODE-HARDLIGHT-LEGACY)
(gimp-layer-set-opacity varBevelLayer 80)
;delete outside the desired bevel
(if (= inLocation 0)
(begin ;inside
(gimp-selection-load varSavedSelection)
(gimp-selection-invert img)
(if (= (car (gimp-selection-is-empty img)) FALSE)
(gimp-edit-clear varBevelLayer)
)
(gimp-selection-load varSavedSelection)
(gimp-selection-shrink img inWidth)
(if (= (car (gimp-selection-is-empty img)) FALSE)
(gimp-edit-clear varBevelLayer)
)
)
(begin ;outside
(gimp-selection-load varSavedSelection)
(if (= (car (gimp-selection-is-empty img)) FALSE)
(gimp-edit-clear varBevelLayer)
)
(gimp-selection-load varSavedSelection)
(gimp-selection-grow img inWidth)
(gimp-selection-invert img)
(if (= (car (gimp-selection-is-empty img)) FALSE)
(gimp-edit-clear varBevelLayer)
)
)
)
; blur if desired
(when (> inBlur 0)
(gimp-selection-load varBlurredSelection)
(if (= inLocation 1)
(gimp-selection-invert img)
)
(plug-in-gauss RUN-NONINTERACTIVE img varBevelLayer inBlur inBlur 0)
(gimp-selection-none img)
)
;delete bumpmap layer
(if (= inKeepBump TRUE)
(gimp-drawable-set-visible varBumpmapLayer FALSE)
(gimp-image-remove-layer img varBumpmapLayer)
)
;load initial selection back up
(if (= varNoSelection TRUE)
(gimp-selection-none img)
(begin
(gimp-selection-load varSavedSelection)
)
)
;and delete the channels
(gimp-image-remove-channel img varSavedSelection)
(gimp-image-remove-channel img varBlurredSelection)
(gimp-image-set-active-layer img varBevelLayer)
;done
;(gimp-progress-end)
(gimp-image-undo-group-end img)
(gimp-displays-flush)
(gimp-context-pop)
)
)