home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 June / june_2001.iso / Multimedia / Images / Gimp / setup.exe / Main / select_to_brush.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2000-10-23  |  4.0 KB  |  106 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-image (car (gimp-image-new selection-width selection-height 1)))
  53.     (set! brush-draw (car (gimp-layer-new brush-image selection-width selection-height GRAY_IMAGE "Sloth" 100 NORMAL)))
  54.     (gimp-image-add-layer brush-image brush-draw 0)
  55.     
  56.     (gimp-selection-none brush-image)
  57.     (gimp-palette-set-background '(255 255 255))
  58.     (gimp-drawable-fill brush-draw BG-IMAGE-FILL)
  59.  
  60.     (let ((floating-sel (car (gimp-edit-paste brush-draw FALSE))))
  61.       (gimp-floating-sel-anchor floating-sel)
  62.       )
  63.  
  64.     (set! data-dir (car (gimp-gimprc-query "gimp_dir")))
  65.     (set! filename2 (string-append data-dir
  66.                      "/brushes/"
  67.                      filename
  68.                      (number->string image)
  69.                      ".gbr"))
  70.  
  71.     (gimp-invert brush-draw)
  72.     (file-gbr-save 1 brush-image brush-draw filename2 "" spacing desc)
  73.     (gimp-brushes-refresh) ; My own modification!  You'll need my diff.
  74.     (gimp-brushes-set-brush desc)
  75.     
  76.     (gimp-palette-set-background old-bg)
  77.  
  78.     ;(set! image_test (gimp-procedural-db-get-data image))
  79.     (print (number->string image))
  80.     (print "this is a test.......test..")
  81.     (gimp-image-undo-enable image)
  82.     (gimp-image-set-active-layer image drawable)
  83.     (gimp-image-delete brush-image)
  84.     (gimp-displays-flush)))
  85.  
  86. (script-fu-register "script-fu-selection-to-brush"
  87.  ; I like this script under the main selection menu, but that doesnt seem quite kosher
  88. ;            "<Image>/Select/Selection To Brush"
  89.             _"<Image>/Script-Fu/Selection/To Brush..."
  90.             "Convert a selection to a greyscale brush"
  91.             "Adrian Likins <adrian@gimp.org>"
  92.             "Adrian Likins"
  93.             "10/07/97"
  94.             "RGB* GRAY*"
  95.             SF-IMAGE "Image" 0
  96.             SF-DRAWABLE "Drawable" 0
  97. ;            SF-STRING "Home directory" "/home/aklikins/"
  98.             SF-STRING _"Description" "Brush"
  99.             SF-STRING _"Filename" "SlothBrush"
  100.             SF-ADJUSTMENT _"Spacing" '(25 0 1000 1 1 1 0))
  101.  
  102.  
  103.