home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 February / PCWorld_2001-02_cd.bin / Software / Topware / gimp / gimp-setup-20001226.exe / Main / addborder.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2000-12-27  |  5.5 KB  |  178 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. ; Copyright (C) 1997 Andy Thomas alt@picnic.demon.co.uk
  16. ;
  17. ; Version 0.2 10.6.97 Changed to new script-fu interface in 0.99.10
  18.  
  19. ; Delta the colour by the given amount. Check for boundary conditions
  20. ; If < 0 set to zero 
  21. ; If > 255 set to 255
  22. ; Return the new value
  23.  
  24. (define (deltacolour col delta)
  25.   (let* ((newcol (+ col delta)))
  26. ;    (print "Old colour -") (print col)
  27.     (if (< newcol 0) (set! newcol 0))
  28.     (if (> newcol 255) (set! newcol 255))
  29. ;    (print "New colour") (print newcol)
  30.     newcol)
  31.   )
  32.  
  33. (define (adjcolour col delta)
  34.   (mapcar (lambda (x) (deltacolour x delta)) col)
  35. )
  36.  
  37. (define (gen_top_array xsize ysize owidth oheight width height)
  38.   (let* ((n_array (cons-array 10 'double)))
  39.     (aset n_array 0 0 )
  40.     (aset n_array 1 0 )
  41.     (aset n_array 2 xsize)
  42.     (aset n_array 3 ysize)
  43.     (aset n_array 4 (+ xsize owidth))
  44.     (aset n_array 5 ysize)
  45.     (aset n_array 6 width)
  46.     (aset n_array 7 0 )
  47.     (aset n_array 8 0 )
  48.     (aset n_array 9 0 )
  49.     n_array)
  50. )
  51.  
  52. (define (gen_left_array xsize ysize owidth oheight width height)
  53.   (let* ((n_array (cons-array 10 'double)))
  54.     (aset n_array 0 0 )
  55.     (aset n_array 1 0 )
  56.     (aset n_array 2 xsize)
  57.     (aset n_array 3 ysize)
  58.     (aset n_array 4 xsize)
  59.     (aset n_array 5 (+ ysize oheight))
  60.     (aset n_array 6 0 )
  61.     (aset n_array 7 height )
  62.     (aset n_array 8 0 )
  63.     (aset n_array 9 0 )
  64.     n_array)
  65. )
  66.  
  67. (define (gen_right_array xsize ysize owidth oheight width height)
  68.   (let* ((n_array (cons-array 10 'double)))
  69.     (aset n_array 0 width )
  70.     (aset n_array 1 0 )
  71.     (aset n_array 2 (+ xsize owidth))
  72.     (aset n_array 3 ysize)
  73.     (aset n_array 4 (+ xsize owidth))
  74.     (aset n_array 5 (+ ysize oheight))
  75.     (aset n_array 6 width)
  76.     (aset n_array 7 height)
  77.     (aset n_array 8 width )
  78.     (aset n_array 9 0 )
  79.     n_array)
  80. )
  81.  
  82. (define (gen_bottom_array xsize ysize owidth oheight width height)
  83.   (let* ((n_array (cons-array 10 'double)))
  84.     (aset n_array 0 0 )
  85.     (aset n_array 1 height)
  86.     (aset n_array 2 xsize)
  87.     (aset n_array 3 (+ ysize oheight))
  88.     (aset n_array 4 (+ xsize owidth))
  89.     (aset n_array 5 (+ ysize oheight))
  90.     (aset n_array 6 width)
  91.     (aset n_array 7 height)
  92.     (aset n_array 8 0 )
  93.     (aset n_array 9 height)
  94.     n_array)
  95. )
  96.  
  97. (define (script-fu-addborder aimg adraw xsize ysize colour dvalue)
  98.   (let* ((img (car (gimp-drawable-image adraw)))
  99.      (owidth (car (gimp-image-width img)))
  100.      (oheight (car (gimp-image-height img)))
  101.      (old-fg (car (gimp-palette-get-foreground)))
  102.          (old-bg (car (gimp-palette-get-background)))
  103.      (width (+ owidth (* 2 xsize)))
  104.      (height (+ oheight (* 2 ysize)))
  105.      (layer (car (gimp-layer-new img width height RGBA_IMAGE "Border-Layer" 100 NORMAL))))
  106. ;Add this for debugging    (verbose 4)
  107.     (gimp-image-undo-disable img)
  108.     (gimp-drawable-fill layer TRANS-IMAGE-FILL)
  109.     (gimp-image-resize img
  110.                width
  111.                    height
  112.                    xsize
  113.                    ysize)
  114.     (gimp-palette-set-background (adjcolour colour dvalue))
  115.     (gimp-free-select img
  116.               10
  117.               (gen_top_array xsize ysize owidth oheight width height)
  118.               REPLACE
  119.               0
  120.               0
  121.               0.0)
  122.     (gimp-edit-fill layer BG-IMAGE-FILL)
  123.     (gimp-palette-set-background (adjcolour colour (/ dvalue 2)))
  124.     (gimp-free-select img
  125.               10
  126.               (gen_left_array xsize ysize owidth oheight width height)
  127.               REPLACE
  128.               0
  129.               0
  130.               0.0)
  131.     (gimp-edit-fill layer BG-IMAGE-FILL)
  132.     (gimp-palette-set-background (adjcolour colour (- 0 (/ dvalue 2))))
  133.     (gimp-free-select img
  134.               10
  135.               (gen_right_array xsize ysize owidth oheight width height)
  136.               REPLACE
  137.               0
  138.               0
  139.               0.0)
  140.  
  141.     (gimp-edit-fill layer BG-IMAGE-FILL)
  142.     (gimp-palette-set-background (adjcolour colour (- 0 dvalue)))
  143.     (gimp-free-select img
  144.               10
  145.               (gen_bottom_array xsize ysize owidth oheight width height)
  146.               REPLACE
  147.               0
  148.               0
  149.               0.0)
  150.  
  151.     (gimp-edit-fill layer BG-IMAGE-FILL)
  152.     (gimp-selection-none img)
  153.     (gimp-image-add-layer img layer 0)
  154.     (gimp-image-undo-enable img)
  155.     (gimp-palette-set-background old-bg)
  156.     (gimp-displays-flush)
  157.     )
  158. )
  159.  
  160.  
  161. (script-fu-register "script-fu-addborder"
  162.             _"<Image>/Script-Fu/Decor/Add Border..."
  163.             "Add a border around an image"
  164.             "Andy Thomas <alt@picnic.demon.co.uk>"
  165.             "Andy Thomas"
  166.             "6/10/97"
  167.             "RGB*"
  168.             SF-IMAGE "Input Image" 0
  169.             SF-DRAWABLE "Input Drawable" 0
  170.             SF-ADJUSTMENT _"Border X Size" '(12 1 250 1 10 0 1)
  171.             SF-ADJUSTMENT _"Border Y Size" '(12 1 250 1 10 0 1)
  172.             SF-COLOR _"Border Color" '(38 31 207)
  173.             SF-ADJUSTMENT _"Delta Value on Color" '(25 1 255 1 10 0 1)
  174.             )
  175.