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 / round-corners.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2004-09-26  |  4.7 KB  |  140 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. ; round-corners.scm   version 1.02   1999/12/21
  17. ;
  18. ; CHANGE-LOG:
  19. ; 1.00 - initial release
  20. ; 1.01 - some code cleanup, no real changes
  21. ;
  22. ; Copyright (C) 1997-1999 Sven Neumann <sven@gimp.org> 
  23. ;  
  24. ;
  25. ; Rounds the corners of an image, optionally adding a drop-shadow and
  26. ; a background layer
  27. ;
  28. ; The script works on RGB and grayscale images that contain only 
  29. ; one layer. It creates a copy of the image or can optionally work 
  30. ; on the original. The script uses the current background color to 
  31. ; create a background layer. It makes a call to the script drop-shadow.
  32. ;
  33. ; This script is derived from my script add-shadow, which has become 
  34. ; obsolet now.
  35.  
  36.  
  37.  
  38. (define (script-fu-round-corners img
  39.                  drawable
  40.                  radius
  41.                  shadow-toggle
  42.                  shadow-x
  43.                  shadow-y
  44.                  shadow-blur
  45.                  background-toggle
  46.                  work-on-copy)
  47.   (let* ((shadow-blur (abs shadow-blur))
  48.      (radius (abs radius))
  49.      (diam (* 2 radius))
  50.      (width (car (gimp-image-width img)))
  51.      (height (car (gimp-image-height img)))
  52.      (type (car (gimp-drawable-type-with-alpha drawable)))
  53.      (image (cond ((= work-on-copy TRUE)
  54.                (car (gimp-image-duplicate img)))
  55.               ((= work-on-copy FALSE)
  56.                img)))
  57.      (pic-layer (car (gimp-image-get-active-drawable image))))
  58.  
  59.   (cond ((= work-on-copy TRUE)
  60.          (gimp-image-undo-disable image))
  61.         ((= work-on-copy FALSE)
  62.          (gimp-image-undo-group-start image)))
  63.  
  64.   ; add an alpha channel to the image
  65.   (gimp-layer-add-alpha pic-layer)
  66.   
  67.   ; round the edges  
  68.   (gimp-selection-none image)
  69.   (gimp-rect-select image 0 0 radius radius CHANNEL-OP-ADD 0 0)
  70.   (gimp-ellipse-select image 0 0 diam diam CHANNEL-OP-SUBTRACT TRUE 0 0)
  71.   (gimp-rect-select image (- width radius) 0 radius radius CHANNEL-OP-ADD 0 0)
  72.   (gimp-ellipse-select image (- width diam) 0 diam diam CHANNEL-OP-SUBTRACT TRUE 0 0)
  73.   (gimp-rect-select image 0 (- height radius) radius radius CHANNEL-OP-ADD 0 0)
  74.   (gimp-ellipse-select image 0 (- height diam) diam diam CHANNEL-OP-SUBTRACT TRUE 0 0)
  75.   (gimp-rect-select image (- width radius) (- height radius)
  76.             radius radius CHANNEL-OP-ADD 0 0)
  77.   (gimp-ellipse-select image (- width diam) (- height diam)
  78.                diam diam CHANNEL-OP-SUBTRACT TRUE 0 0)
  79.   (gimp-edit-clear pic-layer)
  80.   (gimp-selection-none image)
  81.   
  82.   ; optionally add a shadow
  83.   (if (= shadow-toggle TRUE)
  84.       (begin
  85.     (script-fu-drop-shadow image
  86.                    pic-layer
  87.                    shadow-x
  88.                    shadow-y
  89.                    shadow-blur
  90.                    '(0 0 0)
  91.                    80
  92.                    TRUE)
  93.     (set! width (car (gimp-image-width image)))
  94.     (set! height (car (gimp-image-height image)))))
  95.       
  96.   ; optionally add a background
  97.   (if (= background-toggle TRUE)
  98.       (let* ((bg-layer (car (gimp-layer-new image
  99.                         width
  100.                         height
  101.                         type
  102.                         "Background"
  103.                         100
  104.                         NORMAL-MODE))))
  105.     (gimp-drawable-fill bg-layer BACKGROUND-FILL)
  106.     (gimp-image-add-layer image bg-layer -1)
  107.     (gimp-image-raise-layer image pic-layer)
  108.     (if (= shadow-toggle TRUE)
  109.         (gimp-image-lower-layer image bg-layer))))
  110.  
  111. ; clean up after the script
  112.   (cond ((= work-on-copy TRUE)
  113.          (gimp-image-undo-enable image))
  114.         ((= work-on-copy FALSE)
  115.          (gimp-image-undo-group-end image)))
  116.  
  117.   (if (= work-on-copy TRUE)
  118.       (gimp-display-new image))
  119.   (gimp-displays-flush)))
  120.  
  121. (script-fu-register "script-fu-round-corners"
  122.             _"<Image>/Script-Fu/Decor/_Round Corners..."
  123.             "Round the corners of an image and optionally adds a drop-shadow and a background"
  124.             "Sven Neumann <sven@gimp.org>"
  125.             "Sven Neumann"
  126.             "1999/12/21"
  127.             "RGB GRAY"
  128.             SF-IMAGE "Image" 0
  129.             SF-DRAWABLE "Drawable" 0
  130.             SF-ADJUSTMENT _"Edge Radius" '(15 0 4096 1 10 0 1)
  131.             SF-TOGGLE     _"Add Drop-Shadow" TRUE
  132.             SF-ADJUSTMENT _"Shadow X Offset" '(8 -4096 4096 1 10 0 1)
  133.             SF-ADJUSTMENT _"Shadow Y Offset" '(8 -4096 4096 1 10 0 1)
  134.             SF-ADJUSTMENT _"Blur Radius" '(15 0 1024 1 10 0 1)
  135.             SF-TOGGLE     _"Add Background" TRUE
  136.             SF-TOGGLE     _"Work on Copy" TRUE)
  137.