home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 May / maximum-cd-2009-05.iso / DiscContents / gimp-2.6.5-i686-setup.exe / {app} / share / gimp / 2.0 / scripts / round-corners.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2009-02-15  |  5.4 KB  |  145 lines

  1. ; GIMP - The GNU Image Manipulation Program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;
  4. ; This program is free software; you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 2 of the License, or
  7. ; (at your option) any later version.
  8. ;
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ; GNU General Public License for more details.
  13. ;
  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. ;
  19. ; round-corners.scm   version 1.02   1999/12/21
  20. ;
  21. ; CHANGE-LOG:
  22. ; 1.00 - initial release
  23. ; 1.01 - some code cleanup, no real changes
  24. ;
  25. ; Copyright (C) 1997-1999 Sven Neumann <sven@gimp.org>
  26. ;
  27. ;
  28. ; Rounds the corners of an image, optionally adding a drop-shadow and
  29. ; a background layer
  30. ;
  31. ; The script works on RGB and grayscale images that contain only
  32. ; one layer. It creates a copy of the image or can optionally work
  33. ; on the original. The script uses the current background color to
  34. ; create a background layer. It makes a call to the script drop-shadow.
  35. ;
  36. ; This script is derived from my script add-shadow, which has become
  37. ; obsolete now.
  38.  
  39.  
  40.  
  41. (define (script-fu-round-corners img
  42.                                  drawable
  43.                                  radius
  44.                                  shadow-toggle
  45.                                  shadow-x
  46.                                  shadow-y
  47.                                  shadow-blur
  48.                                  background-toggle
  49.                                  work-on-copy)
  50.   (let* ((shadow-blur (abs shadow-blur))
  51.          (radius (abs radius))
  52.          (diam (* 2 radius))
  53.          (width (car (gimp-image-width img)))
  54.          (height (car (gimp-image-height img)))
  55.          (type (car (gimp-drawable-type-with-alpha drawable)))
  56.          (image (cond ((= work-on-copy TRUE)
  57.                        (car (gimp-image-duplicate img)))
  58.                       ((= work-on-copy FALSE)
  59.                        img)))
  60.          (pic-layer (car (gimp-image-get-active-drawable image))))
  61.  
  62.   (if (= work-on-copy TRUE)
  63.       (gimp-image-undo-disable image)
  64.       (gimp-image-undo-group-start image)
  65.   )
  66.  
  67.   ; add an alpha channel to the image
  68.   (gimp-layer-add-alpha pic-layer)
  69.  
  70.   ; round the edges
  71.   (gimp-selection-none image)
  72.   (gimp-rect-select image 0 0 radius radius CHANNEL-OP-ADD 0 0)
  73.   (gimp-ellipse-select image 0 0 diam diam CHANNEL-OP-SUBTRACT TRUE 0 0)
  74.   (gimp-rect-select image (- width radius) 0 radius radius CHANNEL-OP-ADD 0 0)
  75.   (gimp-ellipse-select image (- width diam) 0 diam diam CHANNEL-OP-SUBTRACT TRUE 0 0)
  76.   (gimp-rect-select image 0 (- height radius) radius radius CHANNEL-OP-ADD 0 0)
  77.   (gimp-ellipse-select image 0 (- height diam) diam diam CHANNEL-OP-SUBTRACT TRUE 0 0)
  78.   (gimp-rect-select image (- width radius) (- height radius)
  79.                     radius radius CHANNEL-OP-ADD 0 0)
  80.   (gimp-ellipse-select image (- width diam) (- height diam)
  81.                        diam diam CHANNEL-OP-SUBTRACT TRUE 0 0)
  82.   (gimp-edit-clear pic-layer)
  83.   (gimp-selection-none image)
  84.  
  85.   ; optionally add a shadow
  86.   (if (= shadow-toggle TRUE)
  87.       (begin
  88.         (script-fu-drop-shadow image
  89.                                pic-layer
  90.                                shadow-x
  91.                                shadow-y
  92.                                shadow-blur
  93.                                '(0 0 0)
  94.                                80
  95.                                TRUE)
  96.         (set! width (car (gimp-image-width image)))
  97.         (set! height (car (gimp-image-height image)))))
  98.  
  99.   ; optionally add a background
  100.   (if (= background-toggle TRUE)
  101.       (let* ((bg-layer (car (gimp-layer-new image
  102.                                             width
  103.                                             height
  104.                                             type
  105.                                             "Background"
  106.                                             100
  107.                                             NORMAL-MODE))))
  108.         (gimp-drawable-fill bg-layer BACKGROUND-FILL)
  109.         (gimp-image-add-layer image bg-layer -1)
  110.         (gimp-image-raise-layer image pic-layer)
  111.         (if (= shadow-toggle TRUE)
  112.             (gimp-image-lower-layer image bg-layer))))
  113.  
  114. ; clean up after the script
  115.   (if (= work-on-copy TRUE)
  116.       (gimp-image-undo-enable image)
  117.       (gimp-image-undo-group-end image)
  118.   )
  119.  
  120.   (if (= work-on-copy TRUE)
  121.       (gimp-display-new image))
  122.   (gimp-displays-flush))
  123. )
  124.  
  125. (script-fu-register "script-fu-round-corners"
  126.   _"_Round Corners..."
  127.   _"Round the corners of an image and optionally add a drop-shadow and background"
  128.   "Sven Neumann <sven@gimp.org>"
  129.   "Sven Neumann"
  130.   "1999/12/21"
  131.   "RGB GRAY"
  132.   SF-IMAGE      "Image"            0
  133.   SF-DRAWABLE   "Drawable"         0
  134.   SF-ADJUSTMENT _"Edge radius"     '(15 0 4096 1 10 0 1)
  135.   SF-TOGGLE     _"Add drop-shadow" TRUE
  136.   SF-ADJUSTMENT _"Shadow X offset" '(8 -4096 4096 1 10 0 1)
  137.   SF-ADJUSTMENT _"Shadow Y offset" '(8 -4096 4096 1 10 0 1)
  138.   SF-ADJUSTMENT _"Blur radius"     '(15 0 1024 1 10 0 1)
  139.   SF-TOGGLE     _"Add background"  TRUE
  140.   SF-TOGGLE     _"Work on copy"    TRUE
  141. )
  142.  
  143. (script-fu-menu-register "script-fu-round-corners"
  144.                          "<Image>/Filters/Decor")
  145.