home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 February / PCWorld_2001-02_cd.bin / Software / Topware / gimp / gimp-setup-20001226.exe / Main / alien-neon-logo.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2000-12-27  |  6.9 KB  |  173 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; alien-neon-logo.scm - creates multiple outlines around the letters
  4. ; Copyright (C) 1999-2000 Raphael Quinet <quinet@gamers.org>
  5. ;
  6. ; This program is free software; you can redistribute it and/or modify
  7. ; it under the terms of the GNU General Public License as published by
  8. ; the Free Software Foundation; either version 2 of the License, or
  9. ; (at your option) any later version.
  10. ; This program is distributed in the hope that it will be useful,
  11. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ; GNU General Public License for more details.
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program; if not, write to the Free Software
  16. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ;
  18. ; 1999-12-01 First version.
  19. ; 2000-02-19 Do not discard the layer mask so that it can still be edited.
  20. ; 2000-03-08 Adapted the script to my gimp-edit-fill changes.
  21. ; 2000-04-02 Split the script in two parts: one using text, one using alpha.
  22. ; 2000-05-29 More modifications for "Alpha to Logo" using a separate function.
  23. ;
  24. ; To do: use a channel mask for creating the bands, instead of working in the
  25. ; image.  gimp-invert would then work on one grayscale channel instead of
  26. ; wasting CPU cycles on three identical R, G, B channels.
  27.  
  28. (define (apply-alien-neon-logo-effect img
  29.                       logo-layer
  30.                       fg-color
  31.                       bg-color 
  32.                       band-size 
  33.                       gap-size 
  34.                       num-bands 
  35.                       do-fade)
  36.   (let* ((fade-size (- (* (+ band-size gap-size) num-bands) 1))
  37.      (width (car (gimp-drawable-width logo-layer)))
  38.      (height (car (gimp-drawable-height logo-layer)))
  39.      (bg-layer (car (gimp-layer-new img width height RGB_IMAGE "Background" 100 NORMAL)))
  40.      (bands-layer (car (gimp-layer-new img width height RGBA_IMAGE "Bands" 100 NORMAL)))
  41.      (old-fg (car (gimp-palette-get-foreground)))
  42.      (old-bg (car (gimp-palette-get-background))))
  43.     (gimp-image-resize img width height 0 0)
  44.     (gimp-image-add-layer img bg-layer 1)
  45.     (gimp-image-add-layer img bands-layer 1)
  46.     (gimp-selection-none img)
  47.     (gimp-palette-set-background bg-color)
  48.     (gimp-edit-fill bg-layer BG-IMAGE-FILL)
  49.     (gimp-palette-set-background '(0 0 0))
  50.     (gimp-edit-fill bands-layer BG-IMAGE-FILL)
  51.     ; The text layer is never shown: it is only used to create a selection
  52.     (gimp-selection-layer-alpha logo-layer)
  53.     (gimp-palette-set-foreground '(255 255 255))
  54.     (gimp-edit-fill bands-layer FG-IMAGE-FILL)
  55.  
  56.     ; Create multiple outlines by growing and inverting the selection
  57.     ; The bands are black and white because they will be used as a mask.
  58.     (while (> num-bands 0)
  59.        (gimp-selection-grow img band-size)
  60.        (gimp-invert bands-layer)
  61.        (gimp-selection-grow img gap-size)
  62.        (gimp-invert bands-layer)
  63.        (set! num-bands (- num-bands 1)))
  64.  
  65.     ; The fading effect is obtained by masking the image with a gradient.
  66.     ; The gradient is created by filling a bordered selection (white->black).
  67.     (if (= do-fade TRUE)
  68.     (let ((bands-layer-mask (car (gimp-layer-create-mask bands-layer
  69.                                  BLACK-MASK))))
  70.       (gimp-image-add-layer-mask img bands-layer bands-layer-mask)
  71.       (gimp-selection-layer-alpha logo-layer)
  72.       (gimp-selection-border img fade-size)
  73.       (gimp-edit-fill bands-layer-mask FG-IMAGE-FILL)
  74.       (gimp-image-remove-layer-mask img bands-layer APPLY)))
  75.  
  76.     ; Transfer the resulting grayscale bands into the layer mask.
  77.     (let ((bands-layer-mask (car (gimp-layer-create-mask bands-layer
  78.                              BLACK-MASK))))
  79.       (gimp-image-add-layer-mask img bands-layer bands-layer-mask)
  80.       (gimp-selection-none img)
  81.       (gimp-edit-copy bands-layer)
  82.       (gimp-floating-sel-anchor (car (gimp-edit-paste bands-layer-mask
  83.                               FALSE))))
  84.  
  85.     ; Fill the layer with the foreground color.  The areas that are not
  86.     ; masked become visible.
  87.     (gimp-palette-set-foreground fg-color)
  88.     (gimp-edit-fill bands-layer FG-IMAGE-FILL)
  89.     ;; (gimp-image-remove-layer-mask img bands-layer APPLY)
  90.  
  91.     ; Clean up and exit.
  92.     (gimp-palette-set-foreground old-fg)
  93.     (gimp-palette-set-background old-bg)
  94.     (gimp-layer-set-visible logo-layer 0)
  95.     (gimp-image-set-active-layer img bands-layer)
  96.     (gimp-displays-flush)))
  97.  
  98. (define (script-fu-alien-neon-logo-alpha img
  99.                      logo-layer
  100.                      fg-color
  101.                      bg-color
  102.                      band-size
  103.                      gap-size
  104.                      num-bands
  105.                      do-fade)
  106.   (begin
  107.     (gimp-undo-push-group-start img)
  108.     (apply-alien-neon-logo-effect img logo-layer fg-color bg-color 
  109.                   band-size gap-size num-bands do-fade)
  110.     (gimp-undo-push-group-end img)
  111.     (gimp-displays-flush)))
  112.  
  113. (script-fu-register "script-fu-alien-neon-logo-alpha"
  114.             _"<Image>/Script-Fu/Alpha to Logo/Alien Neon..."
  115.             "Creates a psychedelic effect with outlines of the specified color around the letters"
  116.             "Raphael Quinet (quinet@gamers.org)"
  117.             "Raphael Quinet"
  118.             "1999-2000"
  119.             "RGBA"
  120.                     SF-IMAGE      "Image" 0
  121.                     SF-DRAWABLE   "Drawable" 0
  122.             SF-COLOR      _"Glow Color" '(0 255 0)
  123.             SF-COLOR      _"Background Color" '(0 0 0)
  124.                     SF-ADJUSTMENT _"Width of Bands" '(2 1 60 1 10 0 0)
  125.                     SF-ADJUSTMENT _"Width of Gaps" '(2 1 60 1 10 0 0)
  126.                     SF-ADJUSTMENT _"Number of Bands" '(7 1 100 1 10 0 1)
  127.             SF-TOGGLE     _"Fade Away" TRUE
  128.             )
  129.  
  130. (define (script-fu-alien-neon-logo text 
  131.                    size 
  132.                    fontname 
  133.                    fg-color 
  134.                    bg-color 
  135.                    band-size 
  136.                    gap-size 
  137.                    num-bands 
  138.                    do-fade)
  139.   (let* ((img (car (gimp-image-new 256 256 RGB)))
  140.      (fade-size (- (* (+ band-size gap-size) num-bands) 1))
  141.      (text-layer (car (gimp-text-fontname img -1 0 0 text (+ fade-size 10) TRUE size PIXELS fontname))))
  142.     (gimp-image-undo-disable img)
  143.     (gimp-layer-set-name text-layer text)
  144.     (apply-alien-neon-logo-effect img text-layer fg-color bg-color
  145.                   band-size gap-size num-bands do-fade)
  146.     (gimp-image-undo-enable img)
  147.     (gimp-display-new img)))
  148.  
  149. (script-fu-register "script-fu-alien-neon-logo"
  150.             _"<Toolbox>/Xtns/Script-Fu/Logos/Alien Neon..."
  151.             "Creates a psychedelic effect with outlines of the specified color around the letters"
  152.             "Raphael Quinet (quinet@gamers.org)"
  153.             "Raphael Quinet"
  154.             "1999-2000"
  155.             ""
  156.             SF-STRING     _"Text" "The GIMP"
  157.             SF-ADJUSTMENT _"Font Size (pixels)" '(150 2 1000 1 10 0 1)
  158.             SF-FONT       _"Font" "-*-blippo-*-r-*-*-24-*-*-*-p-*-*-*"
  159.             SF-COLOR      _"Glow Color" '(0 255 0)
  160.             SF-COLOR      _"Background Color" '(0 0 0)
  161.                     SF-ADJUSTMENT _"Width of Bands" '(2 1 60 1 10 0 0)
  162.                     SF-ADJUSTMENT _"Width of Gaps" '(2 1 60 1 10 0 0)
  163.                     SF-ADJUSTMENT _"Number of Bands" '(7 1 100 1 10 0 1)
  164.             SF-TOGGLE     _"Fade Away" TRUE
  165.             )
  166.  
  167. ; end
  168.  
  169.