home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 August / ENTER.ISO / files / gimp-2.0.5-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / drop-shadow.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2004-09-26  |  5.7 KB  |  175 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; This program is free software; you can redistribute it and/or modify
  4. ; it under the terms of the GNU General Public License as published by
  5. ; the Free Software Foundation; either version 2 of the License, or
  6. ; (at your option) any later version.  
  7. ; This program is distributed in the hope that it will be useful,
  8. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10. ; GNU General Public License for more details.
  11. ; You should have received a copy of the GNU General Public License
  12. ; along with this program; if not, write to the Free Software
  13. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. ;
  15. ;
  16. ; drop-shadow.scm   version 1.04   1999/12/21 
  17. ;
  18. ; CHANGE-LOG:
  19. ; 1.00 - initial release
  20. ; 1.01 - fixed the problem with a remaining copy of the selection
  21. ; 1.02 - some code cleanup, no real changes
  22. ; 1.03 - can't call gimp-edit-fill until layer is added to image!
  23. ;
  24. ;
  25. ; Copyright (C) 1997-1999 Sven Neumann <sven@gimp.org>
  26. ;  
  27. ; Adds a drop-shadow of the current selection or alpha-channel. 
  28. ;
  29. ; This script is derived from my script add-shadow, which has become 
  30. ; obsolete now. Thanks to Andrew Donkin (ard@cs.waikato.ac.nz) for his 
  31. ; idea to add alpha-support to add-shadow.
  32.  
  33.   
  34. (define (script-fu-drop-shadow image
  35.                    drawable
  36.                    shadow-transl-x
  37.                    shadow-transl-y
  38.                    shadow-blur
  39.                    shadow-color
  40.                    shadow-opacity
  41.                    allow-resize)
  42.   (let* ((shadow-blur (max shadow-blur 0))
  43.      (shadow-opacity (min shadow-opacity 100))
  44.      (shadow-opacity (max shadow-opacity 0))
  45.      (type (car (gimp-drawable-type-with-alpha drawable)))
  46.      (image-width (car (gimp-image-width image)))
  47.      (image-height (car (gimp-image-height image)))
  48.      (old-bg (car (gimp-palette-get-background)))
  49.      (from-selection 0)
  50.      (active-selection 0)
  51.      (shadow-layer 0))
  52.  
  53.   (gimp-image-set-active-layer image drawable)
  54.  
  55.   (gimp-image-undo-group-start image)
  56.   
  57.   (gimp-layer-add-alpha drawable)
  58.   (if (= (car (gimp-selection-is-empty image)) TRUE)
  59.       (begin
  60.     (gimp-selection-layer-alpha drawable)
  61.     (set! from-selection FALSE))
  62.       (begin
  63.     (set! from-selection TRUE)
  64.     (set! active-selection (car (gimp-selection-save image)))))
  65.   
  66.   (let* ((selection-bounds (gimp-selection-bounds image))
  67.      (select-offset-x (cadr selection-bounds))
  68.      (select-offset-y (caddr selection-bounds))
  69.      (select-width (- (cadr (cddr selection-bounds)) select-offset-x))
  70.      (select-height (- (caddr (cddr selection-bounds)) select-offset-y))
  71.   
  72.      (shadow-width (+ select-width (* 2 shadow-blur)))
  73.      (shadow-height (+ select-height (* 2 shadow-blur)))
  74.  
  75.      (shadow-offset-x (- select-offset-x shadow-blur))
  76.      (shadow-offset-y (- select-offset-y shadow-blur)))
  77.  
  78.     (if (= allow-resize TRUE)
  79.     (let* ((new-image-width image-width)
  80.            (new-image-height image-height)
  81.            (image-offset-x 0)
  82.            (image-offset-y 0))
  83.  
  84.       (if (< (+ shadow-offset-x shadow-transl-x) 0)
  85.           (begin
  86.         (set! image-offset-x (- 0 (+ shadow-offset-x
  87.                          shadow-transl-x)))
  88.         (set! shadow-offset-x (- 0 shadow-transl-x))
  89.         (set! new-image-width (- new-image-width image-offset-x))))
  90.  
  91.       (if (< (+ shadow-offset-y shadow-transl-y) 0)
  92.           (begin
  93.         (set! image-offset-y (- 0 (+ shadow-offset-y
  94.                          shadow-transl-y)))
  95.         (set! shadow-offset-y (- 0 shadow-transl-y))
  96.         (set! new-image-height (- new-image-height image-offset-y))))
  97.  
  98.       (if (> (+ (+ shadow-width shadow-offset-x) shadow-transl-x)
  99.          new-image-width)
  100.           (set! new-image-width
  101.             (+ (+ shadow-width shadow-offset-x) shadow-transl-x)))
  102.  
  103.       (if (> (+ (+ shadow-height shadow-offset-y) shadow-transl-y)
  104.          new-image-height)
  105.           (set! new-image-height
  106.             (+ (+ shadow-height shadow-offset-y) shadow-transl-y)))
  107.  
  108.       (gimp-image-resize image
  109.                  new-image-width
  110.                  new-image-height
  111.                  image-offset-x
  112.                  image-offset-y)))
  113.  
  114.  
  115.     (set! shadow-layer (car (gimp-layer-new image
  116.                         shadow-width
  117.                         shadow-height
  118.                         type
  119.                         "Drop-Shadow"
  120.                         shadow-opacity
  121.                         NORMAL-MODE)))
  122.    (gimp-image-add-layer image shadow-layer -1)
  123.     (gimp-layer-set-offsets shadow-layer
  124.                 shadow-offset-x
  125.                 shadow-offset-y))
  126.  
  127.   (gimp-drawable-fill shadow-layer TRANSPARENT-FILL)
  128.   (gimp-palette-set-background shadow-color)
  129.   (gimp-edit-fill shadow-layer BACKGROUND-FILL)
  130.   (gimp-selection-none image)
  131.   (gimp-layer-set-preserve-trans shadow-layer FALSE)
  132.   (if (>= shadow-blur 1.0) (plug-in-gauss-rle 1
  133.                           image
  134.                           shadow-layer
  135.                           shadow-blur
  136.                           TRUE
  137.                           TRUE))
  138.   (gimp-layer-translate shadow-layer shadow-transl-x shadow-transl-y)
  139.  
  140.   (if (= from-selection TRUE)
  141.       (begin
  142.     (gimp-selection-load active-selection)
  143.     (gimp-edit-clear shadow-layer)
  144.     (gimp-image-remove-channel image active-selection)))
  145.  
  146.   (if (and
  147.        (= (car (gimp-layer-is-floating-sel drawable)) 0)
  148.        (= from-selection FALSE))
  149.       (gimp-image-raise-layer image drawable))
  150.  
  151.   (gimp-image-set-active-layer image drawable)
  152.   (gimp-palette-set-background old-bg)
  153.   (gimp-image-undo-group-end image)
  154.   (gimp-displays-flush)))
  155.  
  156. (script-fu-register "script-fu-drop-shadow"
  157.             _"<Image>/Script-Fu/Shadow/_Drop-Shadow..."
  158.             "Add a drop-shadow of the current selection or alpha-channel"
  159.             "Sven Neumann <sven@gimp.org>"
  160.             "Sven Neumann"
  161.             "1999/12/21"
  162.             "RGB* GRAY*"
  163.             SF-IMAGE "Image" 0
  164.             SF-DRAWABLE "Drawable" 0
  165.             SF-ADJUSTMENT _"Offset X" '(8 -4096 4096 1 10 0 1)
  166.             SF-ADJUSTMENT _"Offset Y" '(8 -4096 4096 1 10 0 1)
  167.             SF-ADJUSTMENT _"Blur Radius" '(15 0 1024 1 10 0 1)
  168.             SF-COLOR      _"Color" '(0 0 0)
  169.             SF-ADJUSTMENT _"Opacity" '(80 0 100 1 10 0 0)
  170.             SF-TOGGLE     _"Allow Resizing" TRUE)
  171.