; The GIMP -- an image manipulation program ; Copyright (C) 1995 Spencer Kimball and Peter Mattis ; ; This program is free software; you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation; either version 2 of the License, or ; (at your option) any later version. ; ; 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. ; ; You should have received a copy of the GNU General Public License ; along with this program; if not, write to the Free Software ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ; ; ----------------------------------------------------------------- ; selection-rounded-selection version 0.1.3 2005/03/17 ; Copyright (C) 2004 Eric Pierce ; ; CHANGE-LOG: ; 2005.03.17 0.1.3 - Added list of all level settings to ensure tight edging on rounded selection. ; 2004.11.20 0.1.2 - Fixed to work with layers that have smaller bounding box than image size. ; 2004.11.08 0.1.1 - Minor fixes for 2.2-pre1 ; 2004.10.24 0.1.0 - Initial release ; ; Description: ; Rounds the corners of a selection. ; If no selection exists, a selection is made of the entire layer size and the corners are rounded. ; ; The script works on RGB, RGBA and grayscale images. ; ; Inspired by Tomcat's indispensable rounded corners tutorial ; http://gug.sunsite.dk/tutorials/rounded-corners/ (define (script-fu-selection-rounded-selection image inLayer radius ) (let* ( (img_width (car (gimp-image-width image))) (img_height (car (gimp-image-height image))) (white '(255 255 255)) (black '(0 0 0)) ; List of all black/white level settings for a radius of 1 through 80 (b-and-w '( (0 0) ;0 (41 212) (70 183) (84 169) (93 160) (97 155) (102 151) (105 148) (108 145) (110 143) (111 142) ;10 (112 141) (114 139) (114 139) (115 138) (116 137) (117 136) (117 136) (118 135) (118 135) (119 134) ;20 (119 134) (119 134) (120 134) (120 133) (120 133) (120 133) (121 133) (121 132) (121 132) (121 132) ;30 (121 132) (121 132) (122 131) (122 131) (122 131) (122 131) (122 131) (122 131) (122 131) (122 131) ;40 (123 131) (123 130) (123 130) (123 130) (123 130) (123 130) (123 130) (123 130) (123 130) (123 130) ;50 (123 130) (123 130) (123 130) (123 130) (124 130) (124 129) (124 129) (124 129) (124 129) (124 129) ;60 (124 129) (124 129) (124 129) (124 129) (124 129) (124 129) (124 129) (124 129) (124 129) (124 129) ;70 (124 129) (124 129) (124 129) (124 129) (124 129) (124 129) (124 129) (124 129) (124 129) (124 129) ;80 (124 129) (125 129) (125 129) (125 129) (125 128) (125 128) (125 128) (125 128) (125 128) (125 128) ;90 (125 128) (125 128) (125 128) (125 128) (125 128) (125 128) (125 128) (125 128) (125 128) (125 128) ;100 )) (black_lvl (car (nth radius b-and-w))) (white_lvl (cadr (nth radius b-and-w))) (type (car (gimp-drawable-type-with-alpha inLayer))) ) (gimp-context-push) (gimp-image-undo-group-start image) ; No selection? Then select entire layer area (if (= 0 (car (gimp-selection-is-empty image))) () (begin (set! inLayer_width (car (gimp-drawable-width inLayer))) (set! inLayer_height (car (gimp-drawable-height inLayer))) (set! inLayer_posx (car (gimp-drawable-offsets inLayer))) (set! inLayer_posy (cadr (gimp-drawable-offsets inLayer))) (gimp-rect-select image inLayer_posx inLayer_posy inLayer_width inLayer_height 0 FALSE 0) ;(gimp-selection-all image) ) ) ; Add 1 pixel all the way around the image. ; This will insure that the script properly rounds the corners ; when a selection is along the image border. (gimp-image-resize image (+ 2 img_width) (+ 2 img_height) 1 1) ; Create layer for selection manips (set! drawable (car (gimp-layer-new image img_width img_height type "Rounded Selection" 100 NORMAL-MODE))) (gimp-image-add-layer image drawable 0) (gimp-layer-resize-to-image-size drawable) (gimp-context-set-foreground white) (gimp-context-set-background black) ; Create a B/W mask of the selection (gimp-edit-fill drawable BACKGROUND-FILL) (gimp-selection-invert image) (gimp-edit-fill drawable FOREGROUND-FILL) (gimp-selection-none image) ; Round corners on mask (plug-in-gauss-iir2 1 image drawable radius radius) (gimp-levels drawable 0 black_lvl white_lvl 1.0 0 255) ; For grayscale images convert to RGB so we can perform ; alpha manips on drawable (if (= type GRAYA-IMAGE) (gimp-image-convert-rgb image) ) ; Create new selection from mask (plug-in-colortoalpha 1 image drawable white) (gimp-selection-layer-alpha drawable) (gimp-image-remove-layer image drawable) (if (= type GRAYA-IMAGE) (gimp-image-convert-grayscale image) ) ; Resize image to remove 1 pixel border created earlier (gimp-image-resize image img_width img_height -1 -1) (gimp-image-undo-group-end image) (gimp-displays-flush) (gimp-context-pop) ) ) (script-fu-register "script-fu-selection-rounded-selection" _"/Select/Modify/R_ounded Selection..." "Rounds the corners of a selection. If no selection exists, a selection is made of the entire layer size and the corners are rounded." "Eric Pierce " "Eric Pierce" "2004/10/24" "RGB* GRAY*" SF-IMAGE "The image" 0 SF-DRAWABLE "The layer" 0 SF-ADJUSTMENT _"Radius (px)" '(10 1 120 1 1 0 0) )