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

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; Selection to Image
  4. ; Copyright (c) 1997 Adrian Likins
  5. ; aklikins@eos.ncsu.edu
  6. ;
  7. ; Takes the Current selection and saves it as a seperate image.
  8. ;
  9. ;
  10. ; This program is free software; you can redistribute it and/or modify
  11. ; it under the terms of the GNU General Public License as published by
  12. ; the Free Software Foundation; either version 2 of the License, or
  13. ; (at your option) any later version.
  14. ; This program is distributed in the hope that it will be useful,
  15. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. ; GNU General Public License for more details.
  18. ; You should have received a copy of the GNU General Public License
  19. ; along with this program; if not, write to the Free Software
  20. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22.  
  23. (define (script-fu-selection-to-image image drawable)
  24.   (let* (
  25.      (draw-type (car (gimp-drawable-type-with-alpha drawable)))
  26.      (image-type (car (gimp-image-base-type image)))
  27.      (old-bg (car (gimp-palette-get-background))))
  28.  
  29.     (set! selection-bounds (gimp-selection-bounds image))
  30.     (set! select-offset-x (cadr selection-bounds))
  31.     (set! select-offset-y (caddr selection-bounds))
  32.     (set! selection-width (- (cadr (cddr selection-bounds)) select-offset-x))
  33.     (set! selection-height (- (caddr (cddr selection-bounds)) select-offset-y))
  34.  
  35.     (gimp-image-undo-disable image)
  36.     
  37.     (if (= (car (gimp-selection-is-empty image)) TRUE)
  38.     (begin
  39.       (gimp-selection-layer-alpha drawable)
  40.       (set! active-selection (car (gimp-selection-save image)))
  41.       (set! from-selection FALSE))
  42.     (begin
  43.       (set! from-selection TRUE)
  44.       (set! active-selection (car (gimp-selection-save image)))))
  45.  
  46.     (gimp-edit-copy drawable)
  47.  
  48.     (set! new-image (car (gimp-image-new selection-width selection-height image-type)))
  49.     (set! new-draw (car (gimp-layer-new new-image selection-width selection-height draw-type "Selection" 100 NORMAL)))
  50.     (gimp-image-add-layer new-image new-draw 0)
  51.     (gimp-drawable-fill new-draw BG-IMAGE-FILL)
  52.  
  53.     (let ((floating-sel (car (gimp-edit-paste new-draw FALSE))))
  54.       (gimp-floating-sel-anchor floating-sel)
  55.       )
  56.  
  57.     (gimp-palette-set-background old-bg)
  58.     (gimp-image-undo-enable image)
  59.     (gimp-image-set-active-layer image drawable)
  60.     (gimp-display-new new-image)
  61.     (gimp-displays-flush)
  62. ;    (script-fu-export-file 1 img drawable RGB 255 FALSE 2 "-export" "png")
  63.  
  64. ))
  65.  
  66. (script-fu-register "script-fu-selection-to-image"
  67. ; I prefer this to go under the main selection menu, but this seems more 
  68. ; approriate for mass consumption
  69. ;            "<Image>/Select/Selection to Image"
  70.             _"<Image>/Script-Fu/Selection/To Image"
  71.             "Convert a selection to an image"
  72.             "Adrian Likins <adrian@gimp.org>"
  73.             "Adrian Likins"
  74.             "10/07/97"
  75.             "RGB* GRAY*"
  76.             SF-IMAGE "Image" 0
  77.             SF-DRAWABLE "Drawable" 0)
  78.