home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 June / june_2001.iso / Multimedia / Images / Gimp / setup.exe / Main / round-corners.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2000-10-23  |  4.5 KB  |  133 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-channel-ops-duplicate img)))
  55.               ((= work-on-copy FALSE)
  56.                img)))
  57.      (pic-layer (car (gimp-image-active-drawable image))))
  58.  
  59.   (gimp-image-undo-disable image)
  60.  
  61.   ; add an alpha channel to the image
  62.   (gimp-layer-add-alpha pic-layer)
  63.   
  64.   ; round the edges  
  65.   (gimp-selection-none image)
  66.   (gimp-rect-select image 0 0 radius radius ADD 0 0)
  67.   (gimp-ellipse-select image 0 0 diam diam SUB TRUE 0 0)
  68.   (gimp-rect-select image (- width radius) 0 radius radius ADD 0 0)
  69.   (gimp-ellipse-select image (- width diam) 0 diam diam SUB TRUE 0 0)
  70.   (gimp-rect-select image 0 (- height radius) radius radius ADD 0 0)
  71.   (gimp-ellipse-select image 0 (- height diam) diam diam SUB TRUE 0 0)
  72.   (gimp-rect-select image (- width radius) (- height radius)
  73.             radius radius ADD 0 0)
  74.   (gimp-ellipse-select image (- width diam) (- height diam)
  75.                diam diam SUB TRUE 0 0)
  76.   (gimp-edit-clear pic-layer)
  77.   (gimp-selection-none image)
  78.   
  79.   ; optionally add a shadow
  80.   (if (= shadow-toggle TRUE)
  81.       (begin
  82.     (script-fu-drop-shadow image
  83.                    pic-layer
  84.                    shadow-x
  85.                    shadow-y
  86.                    shadow-blur
  87.                    '(0 0 0)
  88.                    80
  89.                    TRUE)
  90.     (set! width (car (gimp-image-width image)))
  91.     (set! height (car (gimp-image-height image)))))
  92.       
  93.   ; optionally add a background
  94.   (if (= background-toggle TRUE)
  95.       (let* ((bg-layer (car (gimp-layer-new image
  96.                         width
  97.                         height
  98.                         type
  99.                         "Background"
  100.                         100
  101.                         NORMAL))))
  102.     (gimp-drawable-fill bg-layer BG-IMAGE-FILL)
  103.     (gimp-image-add-layer image bg-layer -1)
  104.     (gimp-image-raise-layer image pic-layer)
  105.     (if (= shadow-toggle TRUE)
  106.         (gimp-image-lower-layer image bg-layer))))
  107.  
  108. ; clean up after the script
  109.   (gimp-image-undo-enable image)
  110.   (if (= work-on-copy TRUE)
  111.       (gimp-display-new image))
  112.   (gimp-displays-flush)))
  113.  
  114. (script-fu-register "script-fu-round-corners"
  115.             _"<Image>/Script-Fu/Decor/Round Corners..."
  116.             "Round the corners of an image and optionally adds a drop-shadow and a background"
  117.             "Sven Neumann <sven@gimp.org>"
  118.             "Sven Neumann"
  119.             "1999/12/21"
  120.             "RGB GRAY"
  121.             SF-IMAGE "Image" 0
  122.             SF-DRAWABLE "Drawable" 0
  123.             SF-ADJUSTMENT _"Edge Radius" '(15 0 4096 1 10 0 1)
  124.             SF-TOGGLE     _"Add Drop-Shadow" TRUE
  125.             SF-ADJUSTMENT _"Shadow X Offset" '(8 -4096 4096 1 10 0 1)
  126.             SF-ADJUSTMENT _"Shadow Y Offset" '(8 -4096 4096 1 10 0 1)
  127.             SF-ADJUSTMENT _"Blur Radius" '(15 0 1024 1 10 0 1)
  128.             SF-TOGGLE     _"Add Background" TRUE
  129.             SF-TOGGLE     _"Work on Copy" TRUE)
  130.