home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 February / PCWorld_2001-02_cd.bin / Software / Topware / gimp / gimp-setup-20001226.exe / Main / select_to_brush.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2000-12-27  |  4.4 KB  |  124 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;  Selection-to-brush 
  4. ; Copyright (c) 1997 Adrian Likins
  5. ; aklikins@eos.ncsu.edu
  6. ;
  7. ; Takes the current selection, saves it as a brush, and makes it the active brush..
  8. ;
  9. ; NOTE: You need to change the home dir to the approriate place.
  10. ;       Also, in .13 there are bugs in the gbr plugin that might make it sigsegv
  11. ;
  12. ;       Parts of this script from Sven Neuman's Drop-Shadow and 
  13. ;       Seth Burgess's mkbrush scripts.
  14. ;
  15. ; This program is free software; you can redistribute it and/or modify
  16. ; it under the terms of the GNU General Public License as published by
  17. ; the Free Software Foundation; either version 2 of the License, or
  18. ; (at your option) any later version.
  19. ; This program is distributed in the hope that it will be useful,
  20. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22. ; GNU General Public License for more details.
  23. ; You should have received a copy of the GNU General Public License
  24. ; along with this program; if not, write to the Free Software
  25. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26.  
  27.  
  28. (define (script-fu-selection-to-brush image drawable desc filename spacing)
  29.   (let* (
  30.      (type (car (gimp-drawable-type-with-alpha drawable)))
  31.      (old-bg (car (gimp-palette-get-background))))
  32.   
  33.     (set! selection-bounds (gimp-selection-bounds image))
  34.     (set! select-offset-x (cadr selection-bounds))
  35.     (set! select-offset-y (caddr selection-bounds))
  36.     (set! selection-width (- (cadr (cddr selection-bounds)) select-offset-x))
  37.     (set! selection-height (- (caddr (cddr selection-bounds)) select-offset-y))
  38.  
  39.     (gimp-image-undo-disable image)
  40.     
  41.     (if (= (car (gimp-selection-is-empty image)) TRUE)
  42.     (begin
  43.       (gimp-selection-layer-alpha drawable)
  44.       (set! active-selection (car (gimp-selection-save image)))
  45.       (set! from-selection FALSE))
  46.     (begin
  47.       (set! from-selection TRUE)
  48.       (set! active-selection (car (gimp-selection-save image)))))
  49.  
  50.     (gimp-edit-copy drawable)
  51.  
  52.     (set! brush_draw_type
  53.           (if (= type GRAYA_IMAGE)
  54.               GRAY_IMAGE
  55.               RGBA_IMAGE))
  56.  
  57.     (set! brush_image_type
  58.           (if (= type GRAYA_IMAGE)
  59.               GRAY
  60.               RGB))
  61.  
  62.     (set! brush-image (car (gimp-image-new selection-width selection-height brush_image_type)))
  63.     
  64.     (set! brush-draw
  65.           (car (gimp-layer-new brush-image
  66.                                selection-width
  67.                                selection-height brush_draw_type "Sloth" 100 NORMAL)))
  68.         
  69.     (gimp-image-add-layer brush-image brush-draw 0)
  70.     
  71.     (gimp-selection-none brush-image)
  72.  
  73.     (if (= type GRAYA_IMAGE)
  74.         (begin 
  75.           (gimp-palette-set-background '(255 255 255))
  76.           (gimp-drawable-fill brush-draw BG-IMAGE-FILL)))
  77.  
  78.     (let ((floating-sel (car (gimp-edit-paste brush-draw FALSE))))
  79.       (gimp-floating-sel-anchor floating-sel))
  80.  
  81.     
  82.     (set! data-dir (car (gimp-gimprc-query "gimp_dir")))
  83.     (set! filename2 (string-append data-dir
  84.                      "/brushes/"
  85.                      filename
  86.                      (number->string image)
  87.                      ".gbr"))
  88.  
  89.     ; (gimp-invert brush-draw)
  90.     (file-gbr-save 1 brush-image brush-draw filename2 "" spacing desc)
  91.     (gimp-brushes-refresh) ; My own modification!  You'll need my diff.
  92.     (gimp-brushes-set-brush desc)
  93.     
  94.     (gimp-palette-set-background old-bg)
  95.  
  96.     ;(set! image_test (gimp-procedural-db-get-data image))
  97.     (print (number->string image))
  98.     (print "this is a test.......test..")
  99.     (gimp-image-undo-enable image)
  100.     (gimp-image-set-active-layer image drawable)
  101.     (gimp-image-delete brush-image)
  102.     (gimp-displays-flush)))
  103.  
  104. (script-fu-register "script-fu-selection-to-brush"
  105.  ; I like this script under the main selection menu, but that doesnt seem quite kosher
  106. ;            "<Image>/Select/Selection To Brush"
  107.             _"<Image>/Script-Fu/Selection/To Brush..."
  108.             "Convert a selection to a greyscale brush"
  109.             "Adrian Likins <adrian@gimp.org>"
  110.             "Adrian Likins"
  111.             "10/07/97"
  112.             "RGB* GRAY*"
  113.             SF-IMAGE "Image" 0
  114.             SF-DRAWABLE "Drawable" 0
  115. ;            SF-STRING "Home directory" "/home/aklikins/"
  116.             SF-STRING _"Description" "Brush"
  117.             SF-STRING _"Filename" "SlothBrush"
  118.             SF-ADJUSTMENT _"Spacing" '(25 0 1000 1 1 1 0))
  119.  
  120.  
  121.