; 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. ; ; _\|/_ ; (o o) ; +----oOO-{_}-OOo--------------------------------------------------------+ ; | | ; | script-fu-add-border-f3t | ; | | ; | Draw flat 3-tiered border around an image. Create border on separate | ; | border layer. Allow user to flatten the image automatically. | ; | | ; +-----------------------------------------------------------------------+ ; ; Copyright (c) 2001 Thomas Jensen ; ; Version 0.9 Ported script to Gimp Version 1.2.3 ; 2002-06-14 Did some improvements along the way, e.g. undo handling ; Version 0.8 Added text string functionality ; 2001-09-30 ; Version 0.1 Original Version ; 2001-04-26 This was inspired by script-fu-addborder, which was written ; by Andy Thomas ; ; TODO: ; * add input error checking (too many zeros, negative values) ; (define (move-text-to img tposx tposy tlayer t-ext) (let* ((twidth (car t-ext)) (theight (cadr t-ext)) (nposx (- (car (gimp-image-width img)) twidth (abs tposx))) (nposy (- (car (gimp-image-height img)) theight (abs tposy)))) (gimp-layer-translate tlayer (- (if (< tposx 0) nposx tposx) 2) (- (if (< tposy 0) nposy tposy) 2) ) ) ) (define (script-fu-add-border-f3t aimg adraw ixsize iysize icolour xsize ysize colour oxsize oysize ocolour tstr tposx tposy tcolour tsize tantialias flatimage) (let* ((img (car (gimp-drawable-image adraw))) (owidth (car (gimp-image-width img))) ; original width (oheight (car (gimp-image-height img))) ; original height (old-fg (car (gimp-palette-get-foreground))) (old-bg (car (gimp-palette-get-background))) (width (+ owidth (* 2 oxsize) (* 2 xsize) (* 2 ixsize))) ; new image size (incl. border) (height (+ oheight (* 2 oysize) (* 2 ysize) (* 2 iysize))) (layer (car (gimp-layer-new img width height RGBA_IMAGE "Border Layer" 100 NORMAL)))) (gimp-undo-push-group-start img) (gimp-drawable-fill layer TRANS-IMAGE-FILL) (gimp-image-resize img ; resize to new size incl. border width height (+ oxsize xsize ixsize) (+ oysize ysize iysize)) (gimp-palette-set-background icolour) ; Draw inner border (gimp-rect-select img (+ oxsize xsize ixsize) (+ oysize ysize iysize) owidth oheight REPLACE 0 0.0) (gimp-selection-invert img) (gimp-edit-fill layer BG-IMAGE-FILL) (gimp-palette-set-background colour) ; Draw middle border (gimp-rect-select img (+ oxsize xsize) (+ oysize ysize) (+ owidth (* 2 ixsize)) (+ oheight (* 2 iysize)) REPLACE 0 0.0) (gimp-selection-invert img) (gimp-edit-fill layer BG-IMAGE-FILL) (gimp-palette-set-background ocolour) ; Draw outer border (gimp-rect-select img oxsize oysize (+ owidth (* 2 ixsize) (* 2 xsize)) (+ oheight (* 2 iysize) (* 2 ysize)) REPLACE 0 0.0) (gimp-selection-invert img) (gimp-edit-fill layer BG-IMAGE-FILL) (gimp-selection-none img) (gimp-image-add-layer img layer 0) (gimp-palette-set-background old-bg) (gimp-palette-set-foreground tcolour) (move-text-to img tposx tposy (car (gimp-text img -1 2 2 tstr 0 tantialias tsize PIXELS "*" "helvetica" "medium" "o" "*" "*" "*" "*")) (gimp-text-get-extents tstr tsize PIXELS "*" "helvetica" "medium" "o" "*" "*" "*" "*") ) (gimp-palette-set-foreground old-fg) (if (= flatimage TRUE) (gimp-image-flatten img) () ) (gimp-undo-push-group-end img) (gimp-displays-flush) ) ) (script-fu-register "script-fu-add-border-f3t" _"/Script-Fu/Decor/3-Tiered Border..." "Add a nice border around an image and add a text" "Thomas Jensen " "Thomas Jensen" "26-Apr-2001" "RGB*" SF-IMAGE "Input Image" 0 SF-DRAWABLE "Input Drawable" 0 SF-VALUE _"Inner Border X size" "1" SF-VALUE _"Inner Border Y size" "1" SF-COLOR _"Inner Border Color" '(255 255 255) SF-VALUE _"Main Border X size" "20" SF-VALUE _"Main Border Y size" "20" SF-COLOR _"Main Border Color" '(0 0 0) SF-VALUE _"Outer Border X size" "1" SF-VALUE _"Outer Border Y size" "1" SF-COLOR _"Outer Border Color" '(255 255 255) SF-VALUE _"Text String" "\"© 2001 Thomas Jensen\"" SF-VALUE _"Text Position X" "-20" SF-VALUE _"Text Position Y" "-1" SF-COLOR _"Text Color" '(255 255 255) SF-VALUE _"Text Size (pixel)" "14" SF-TOGGLE _"Text Antialias?" TRUE SF-TOGGLE _"Flatten Image?" FALSE) ;;EOF