2006-12-10 05:33:38 +08:00
|
|
|
; GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +08:00
|
|
|
; Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
2006-10-16 09:08:54 +08:00
|
|
|
;
|
2009-01-18 06:28:01 +08:00
|
|
|
; This program is free software: you can redistribute it and/or modify
|
1997-11-25 06:05:25 +08:00
|
|
|
; it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
; the Free Software Foundation; either version 3 of the License, or
|
1997-11-25 06:05:25 +08:00
|
|
|
; (at your option) any later version.
|
2006-10-16 09:08:54 +08:00
|
|
|
;
|
1997-11-25 06:05:25 +08:00
|
|
|
; This program is distributed in the hope that it will be useful,
|
|
|
|
; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
; GNU General Public License for more details.
|
2006-10-16 09:08:54 +08:00
|
|
|
;
|
1997-11-25 06:05:25 +08:00
|
|
|
; You should have received a copy of the GNU General Public License
|
2009-01-18 06:28:01 +08:00
|
|
|
; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
;
|
|
|
|
;
|
1999-12-21 21:57:58 +08:00
|
|
|
; round-corners.scm version 1.02 1999/12/21
|
1998-02-17 22:27:46 +08:00
|
|
|
;
|
|
|
|
; CHANGE-LOG:
|
|
|
|
; 1.00 - initial release
|
|
|
|
; 1.01 - some code cleanup, no real changes
|
1997-11-25 06:05:25 +08:00
|
|
|
;
|
2006-10-16 09:08:54 +08:00
|
|
|
; Copyright (C) 1997-1999 Sven Neumann <sven@gimp.org>
|
|
|
|
;
|
1997-11-25 06:05:25 +08:00
|
|
|
;
|
|
|
|
; Rounds the corners of an image, optionally adding a drop-shadow and
|
|
|
|
; a background layer
|
|
|
|
;
|
2006-10-16 09:08:54 +08:00
|
|
|
; The script works on RGB and grayscale images that contain only
|
|
|
|
; one layer. It creates a copy of the image or can optionally work
|
|
|
|
; on the original. The script uses the current background color to
|
1997-11-25 06:05:25 +08:00
|
|
|
; create a background layer. It makes a call to the script drop-shadow.
|
|
|
|
;
|
2006-10-16 09:08:54 +08:00
|
|
|
; This script is derived from my script add-shadow, which has become
|
|
|
|
; obsolete now.
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (script-fu-round-corners img
|
2006-10-16 09:08:54 +08:00
|
|
|
drawable
|
|
|
|
radius
|
|
|
|
shadow-toggle
|
|
|
|
shadow-x
|
|
|
|
shadow-y
|
|
|
|
shadow-blur
|
|
|
|
background-toggle
|
|
|
|
work-on-copy)
|
1997-11-25 06:05:25 +08:00
|
|
|
(let* ((shadow-blur (abs shadow-blur))
|
2006-10-16 09:08:54 +08:00
|
|
|
(radius (abs radius))
|
|
|
|
(diam (* 2 radius))
|
|
|
|
(width (car (gimp-image-width img)))
|
|
|
|
(height (car (gimp-image-height img)))
|
|
|
|
(type (car (gimp-drawable-type-with-alpha drawable)))
|
|
|
|
(image (cond ((= work-on-copy TRUE)
|
|
|
|
(car (gimp-image-duplicate img)))
|
|
|
|
((= work-on-copy FALSE)
|
|
|
|
img)))
|
|
|
|
(pic-layer (car (gimp-image-get-active-drawable image))))
|
|
|
|
|
|
|
|
(if (= work-on-copy TRUE)
|
|
|
|
(gimp-image-undo-disable image)
|
|
|
|
(gimp-image-undo-group-start image)
|
|
|
|
)
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
; add an alpha channel to the image
|
|
|
|
(gimp-layer-add-alpha pic-layer)
|
2006-10-16 09:08:54 +08:00
|
|
|
|
|
|
|
; round the edges
|
1997-11-25 06:05:25 +08:00
|
|
|
(gimp-selection-none image)
|
2004-02-03 19:46:27 +08:00
|
|
|
(gimp-rect-select image 0 0 radius radius CHANNEL-OP-ADD 0 0)
|
|
|
|
(gimp-ellipse-select image 0 0 diam diam CHANNEL-OP-SUBTRACT TRUE 0 0)
|
|
|
|
(gimp-rect-select image (- width radius) 0 radius radius CHANNEL-OP-ADD 0 0)
|
|
|
|
(gimp-ellipse-select image (- width diam) 0 diam diam CHANNEL-OP-SUBTRACT TRUE 0 0)
|
|
|
|
(gimp-rect-select image 0 (- height radius) radius radius CHANNEL-OP-ADD 0 0)
|
|
|
|
(gimp-ellipse-select image 0 (- height diam) diam diam CHANNEL-OP-SUBTRACT TRUE 0 0)
|
1998-11-15 04:46:25 +08:00
|
|
|
(gimp-rect-select image (- width radius) (- height radius)
|
2006-10-16 09:08:54 +08:00
|
|
|
radius radius CHANNEL-OP-ADD 0 0)
|
1998-11-15 04:46:25 +08:00
|
|
|
(gimp-ellipse-select image (- width diam) (- height diam)
|
2006-10-16 09:08:54 +08:00
|
|
|
diam diam CHANNEL-OP-SUBTRACT TRUE 0 0)
|
1998-11-15 04:46:25 +08:00
|
|
|
(gimp-edit-clear pic-layer)
|
1997-11-25 06:05:25 +08:00
|
|
|
(gimp-selection-none image)
|
2006-10-16 09:08:54 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
; optionally add a shadow
|
|
|
|
(if (= shadow-toggle TRUE)
|
|
|
|
(begin
|
2006-10-16 09:08:54 +08:00
|
|
|
(script-fu-drop-shadow image
|
|
|
|
pic-layer
|
|
|
|
shadow-x
|
|
|
|
shadow-y
|
|
|
|
shadow-blur
|
|
|
|
'(0 0 0)
|
|
|
|
80
|
|
|
|
TRUE)
|
|
|
|
(set! width (car (gimp-image-width image)))
|
|
|
|
(set! height (car (gimp-image-height image)))))
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
; optionally add a background
|
|
|
|
(if (= background-toggle TRUE)
|
1998-11-15 04:46:25 +08:00
|
|
|
(let* ((bg-layer (car (gimp-layer-new image
|
2006-10-16 09:08:54 +08:00
|
|
|
width
|
|
|
|
height
|
|
|
|
type
|
|
|
|
"Background"
|
|
|
|
100
|
|
|
|
NORMAL-MODE))))
|
|
|
|
(gimp-drawable-fill bg-layer BACKGROUND-FILL)
|
2011-03-02 15:55:43 +08:00
|
|
|
(gimp-image-insert-layer image bg-layer 0 -1)
|
2011-10-30 14:37:26 +08:00
|
|
|
(gimp-image-raise-item image pic-layer)
|
2006-10-16 09:08:54 +08:00
|
|
|
(if (= shadow-toggle TRUE)
|
2011-10-30 14:37:26 +08:00
|
|
|
(gimp-image-lower-item image bg-layer))))
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
; clean up after the script
|
2006-10-16 09:08:54 +08:00
|
|
|
(if (= work-on-copy TRUE)
|
|
|
|
(gimp-image-undo-enable image)
|
|
|
|
(gimp-image-undo-group-end image)
|
|
|
|
)
|
2004-07-13 00:14:22 +08:00
|
|
|
|
1998-11-15 04:46:25 +08:00
|
|
|
(if (= work-on-copy TRUE)
|
|
|
|
(gimp-display-new image))
|
2006-10-16 09:08:54 +08:00
|
|
|
(gimp-displays-flush))
|
|
|
|
)
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
(script-fu-register "script-fu-round-corners"
|
2006-10-16 09:08:54 +08:00
|
|
|
_"_Round Corners..."
|
|
|
|
_"Round the corners of an image and optionally add a drop-shadow and background"
|
|
|
|
"Sven Neumann <sven@gimp.org>"
|
|
|
|
"Sven Neumann"
|
|
|
|
"1999/12/21"
|
|
|
|
"RGB GRAY"
|
2006-10-21 01:55:14 +08:00
|
|
|
SF-IMAGE "Image" 0
|
|
|
|
SF-DRAWABLE "Drawable" 0
|
2006-10-16 09:08:54 +08:00
|
|
|
SF-ADJUSTMENT _"Edge radius" '(15 0 4096 1 10 0 1)
|
|
|
|
SF-TOGGLE _"Add drop-shadow" TRUE
|
|
|
|
SF-ADJUSTMENT _"Shadow X offset" '(8 -4096 4096 1 10 0 1)
|
|
|
|
SF-ADJUSTMENT _"Shadow Y offset" '(8 -4096 4096 1 10 0 1)
|
|
|
|
SF-ADJUSTMENT _"Blur radius" '(15 0 1024 1 10 0 1)
|
|
|
|
SF-TOGGLE _"Add background" TRUE
|
|
|
|
SF-TOGGLE _"Work on copy" TRUE
|
|
|
|
)
|
2004-11-19 06:44:28 +08:00
|
|
|
|
|
|
|
(script-fu-menu-register "script-fu-round-corners"
|
2006-10-16 09:08:54 +08:00
|
|
|
"<Image>/Filters/Decor")
|