carved-logo.scm 6.19 KB
Newer Older
Kevin Cozens's avatar
Kevin Cozens committed
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
;  CARVE-TEXT
;   Carving, embossing, & stamping
;   Process taken from "The Photoshop 3 WOW! Book"
;   http://www.peachpit.com


(define (carve-brush brush-size)
  (cond ((<= brush-size 5) "Circle (05)")
        ((<= brush-size 7) "Circle (07)")
        ((<= brush-size 9) "Circle (09)")
        ((<= brush-size 11) "Circle (11)")
        ((<= brush-size 13) "Circle (13)")
        ((<= brush-size 15) "Circle (15)")
        ((<= brush-size 17) "Circle (17)")
        ((> brush-size 17) "Circle (19)")))

(define (carve-scale val scale)
  (* (sqrt val) scale))

(define (calculate-inset-gamma img layer)
  (let* ((stats (gimp-histogram layer 0 0 255))
         (mean (car stats)))
    (cond ((< mean 127) (+ 1.0 (* 0.5 (/ (- 127 mean) 127.0))))
          ((>= mean 127) (- 1.0 (* 0.5 (/ (- mean 127) 127.0)))))))

26
(define (script-fu-carved-logo text size font bg-img carve-raised padding)
Kevin Cozens's avatar
Kevin Cozens committed
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
  (let* (
        (img (car (gimp-file-load 1 bg-img bg-img)))
        (offx (carve-scale size 0.33))
        (offy (carve-scale size 0.25))
        (feather (carve-scale size 0.3))
        (brush-size (carve-scale size 0.3))
        (b-size (+ (carve-scale size 0.5) padding))
        (layer1 (car (gimp-image-get-active-drawable img)))
        (mask-layer (car (gimp-text-fontname img -1 0 0 text b-size TRUE size PIXELS font)))
        (width (car (gimp-drawable-width mask-layer)))
        (height (car (gimp-drawable-height mask-layer)))
        (mask-fs 0)
        (mask (car (gimp-channel-new img width height "Engraving Mask" 50 '(0 0 0))))
        (inset-gamma (calculate-inset-gamma img layer1))
        (mask-fat 0)
        (mask-emboss 0)
        (mask-highlight 0)
        (mask-shadow 0)
        (shadow-layer 0)
        (highlight-layer 0)
        (cast-shadow-layer 0)
        (csl-mask 0)
        (inset-layer 0)
        (il-mask 0)
        )

    (gimp-context-push)
Kevin Cozens's avatar
Kevin Cozens committed
54

Kevin Cozens's avatar
Kevin Cozens committed
55 56 57 58
    (gimp-image-undo-disable img)

    (gimp-image-set-filename img "")

59 60
    (gimp-image-add-channel img mask 0)

61
    (gimp-layer-set-lock-alpha mask-layer TRUE)
Kevin Cozens's avatar
Kevin Cozens committed
62 63 64 65 66
    (gimp-context-set-background '(255 255 255))
    (gimp-edit-fill mask-layer BACKGROUND-FILL)
    (gimp-context-set-background '(0 0 0))
    (gimp-edit-fill mask BACKGROUND-FILL)

67
    (plug-in-tile RUN-NONINTERACTIVE img layer1 width height FALSE)
Kevin Cozens's avatar
Kevin Cozens committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

    (gimp-edit-copy mask-layer)
    (set! mask-fs (car (gimp-edit-paste mask FALSE)))
    (gimp-floating-sel-anchor mask-fs)
    (if (= carve-raised TRUE)
        (gimp-invert mask)
    )

    (gimp-image-remove-layer img mask-layer)

    (set! mask-fat (car (gimp-channel-copy mask)))
    (gimp-image-add-channel img mask-fat 0)
    (gimp-selection-load mask-fat)
    (gimp-context-set-brush (carve-brush brush-size))
    (gimp-context-set-foreground '(255 255 255))
    (gimp-edit-stroke mask-fat)
    (gimp-selection-none img)

    (set! mask-emboss (car (gimp-channel-copy mask-fat)))
    (gimp-image-add-channel img mask-emboss 0)
88 89
    (plug-in-gauss-rle RUN-NONINTERACTIVE img mask-emboss feather TRUE TRUE)
    (plug-in-emboss RUN-NONINTERACTIVE img mask-emboss 315.0 45.0 7 TRUE)
Kevin Cozens's avatar
Kevin Cozens committed
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

    (gimp-context-set-background '(180 180 180))
    (gimp-selection-load mask-fat)
    (gimp-selection-invert img)
    (gimp-edit-fill mask-emboss BACKGROUND-FILL)
    (gimp-selection-load mask)
    (gimp-edit-fill mask-emboss BACKGROUND-FILL)
    (gimp-selection-none img)

    (set! mask-highlight (car (gimp-channel-copy mask-emboss)))
    (gimp-image-add-channel img mask-highlight 0)
    (gimp-levels mask-highlight 0 180 255 1.0 0 255)

    (set! mask-shadow mask-emboss)
    (gimp-levels mask-shadow 0 0 180 1.0 0 255)

    (gimp-edit-copy mask-shadow)
    (set! shadow-layer (car (gimp-edit-paste layer1 FALSE)))
    (gimp-floating-sel-to-layer shadow-layer)
    (gimp-layer-set-mode shadow-layer MULTIPLY-MODE)

    (gimp-edit-copy mask-highlight)
    (set! highlight-layer (car (gimp-edit-paste shadow-layer FALSE)))
    (gimp-floating-sel-to-layer highlight-layer)
    (gimp-layer-set-mode highlight-layer SCREEN-MODE)

    (gimp-edit-copy mask)
    (set! cast-shadow-layer (car (gimp-edit-paste highlight-layer FALSE)))
    (gimp-floating-sel-to-layer cast-shadow-layer)
    (gimp-layer-set-mode cast-shadow-layer MULTIPLY-MODE)
    (gimp-layer-set-opacity cast-shadow-layer 75)
121
    (plug-in-gauss-rle RUN-NONINTERACTIVE img cast-shadow-layer feather TRUE TRUE)
Kevin Cozens's avatar
Kevin Cozens committed
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
    (gimp-layer-translate cast-shadow-layer offx offy)

    (set! csl-mask (car (gimp-layer-create-mask cast-shadow-layer ADD-BLACK-MASK)))
    (gimp-layer-add-mask cast-shadow-layer csl-mask)
    (gimp-selection-load mask)
    (gimp-context-set-background '(255 255 255))
    (gimp-edit-fill csl-mask BACKGROUND-FILL)

    (set! inset-layer (car (gimp-layer-copy layer1 TRUE)))
    (gimp-image-add-layer img inset-layer 1)

    (set! il-mask (car (gimp-layer-create-mask inset-layer ADD-BLACK-MASK)))
    (gimp-layer-add-mask inset-layer il-mask)
    (gimp-selection-load mask)
    (gimp-context-set-background '(255 255 255))
    (gimp-edit-fill il-mask BACKGROUND-FILL)
    (gimp-selection-none img)

    (gimp-levels inset-layer 0 0 255 inset-gamma 0 255)

    (gimp-image-remove-channel img mask)
    (gimp-image-remove-channel img mask-fat)
    (gimp-image-remove-channel img mask-highlight)
    (gimp-image-remove-channel img mask-shadow)

    (gimp-drawable-set-name layer1 "Carved Surface")
    (gimp-drawable-set-name shadow-layer "Bevel Shadow")
    (gimp-drawable-set-name highlight-layer "Bevel Highlight")
    (gimp-drawable-set-name cast-shadow-layer "Cast Shadow")
    (gimp-drawable-set-name inset-layer "Inset")

Kevin Cozens's avatar
Kevin Cozens committed
153
    (gimp-display-new img)
Kevin Cozens's avatar
Kevin Cozens committed
154
    (gimp-image-undo-enable img)
Kevin Cozens's avatar
Kevin Cozens committed
155

Kevin Cozens's avatar
Kevin Cozens committed
156 157 158 159
    (gimp-context-pop)
  )
)

160
(script-fu-register "script-fu-carved-logo"
161 162 163 164 165 166 167 168 169 170 171 172 173 174
  _"Carved..."
  _"Create a logo with text raised above or carved in to the specified background image"
  "Spencer Kimball"
  "Spencer Kimball"
  "1997"
  ""
  SF-STRING     _"Text" "Marble"
  SF-ADJUSTMENT _"Font size (pixels)" '(100 2 1000 1 10 0 1)
  SF-FONT       _"Font" "Engraver"
  SF-FILENAME   _"Background Image"
      (string-append gimp-data-directory
                     "/scripts/images/texture3.jpg")
  SF-TOGGLE     _"Carve raised text" FALSE
  SF-ADJUSTMENT _"Padding around text" '(10 0 1000 1 10 0 1)
Kevin Cozens's avatar
Kevin Cozens committed
175
)
176

177
(script-fu-menu-register "script-fu-carved-logo"
Kevin Cozens's avatar
Kevin Cozens committed
178
                         "<Toolbox>/Xtns/Logos")