GIMP Script-fu

Artifact [44019253cb]
Login

Artifact 44019253cbb72ae74415b72a81700f9bfdd0da7f:


; 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.

;; 'isolate' delete everything but the selection contents

(define (script-fu-sg-isolate image drawable)
  (gimp-image-undo-group-start image)
  (gimp-context-push)
  (gimp-context-set-default-colors)
  (let ((orig-sel (car (gimp-selection-save image))))
    (cond
      ((= (car (gimp-drawable-is-layer drawable)) TRUE)
        (gimp-layer-add-alpha drawable)
        (gimp-selection-invert image)
        (gimp-edit-clear drawable)
        (gimp-selection-load orig-sel) )
      ((or (= (car (gimp-drawable-is-channel drawable)) TRUE)
           (= (car (gimp-drawable-is-layer-mask drawable)) TRUE) )
        (gimp-selection-none image)
        (gimp-edit-fill drawable FOREGROUND-FILL)
        (gimp-selection-load orig-sel)
        (gimp-edit-fill drawable BACKGROUND-FILL) ))
    (gimp-image-remove-channel image orig-sel) )
  (gimp-context-pop)        
  (gimp-image-undo-group-end image)
  (gimp-displays-flush)
  )

(script-fu-register "script-fu-sg-isolate"
  "Isolate"
  "Remove all content except the selection"
  "Saul Goode"
  "saulgoode"
  "5/21/2007"
  "*"
  SF-IMAGE    "Image"    0
  SF-DRAWABLE "Drawable" 0
  )
(script-fu-menu-register "script-fu-sg-isolate"
  "<Image>/Edit/Clear"
  )