12
12
; it under the terms of the GNU General Public License as published by
13
13
; the Free Software Foundation; either version 2 of the License, or
14
14
; (at your option) any later version.
16
16
; This program is distributed in the hope that it will be useful,
17
17
; but WITHOUT ANY WARRANTY; without even the implied warranty of
18
18
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
19
; GNU General Public License for more details.
21
21
; You should have received a copy of the GNU General Public License
22
22
; along with this program; if not, write to the Free Software
23
23
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
26
(define (script-fu-selection-to-image image drawable)
27
(let* ((draw-type (car (gimp-drawable-type-with-alpha drawable)))
28
(image-type (car (gimp-image-base-type image)))
29
(selection-bounds (gimp-selection-bounds image))
30
(select-offset-x (cadr selection-bounds))
31
(select-offset-y (caddr selection-bounds))
32
(selection-width (- (cadr (cddr selection-bounds)) select-offset-x))
33
(selection-height (- (caddr (cddr selection-bounds)) select-offset-y)))
28
(draw-type (car (gimp-drawable-type-with-alpha drawable)))
29
(image-type (car (gimp-image-base-type image)))
30
(selection-bounds (gimp-selection-bounds image))
31
(select-offset-x (cadr selection-bounds))
32
(select-offset-y (caddr selection-bounds))
33
(selection-width (- (cadr (cddr selection-bounds)) select-offset-x))
34
(selection-height (- (caddr (cddr selection-bounds)) select-offset-y))
35
41
(gimp-context-push)
37
43
(gimp-image-undo-disable image)
39
45
(if (= (car (gimp-selection-is-empty image)) TRUE)
41
(gimp-selection-layer-alpha drawable)
42
(set! active-selection (car (gimp-selection-save image)))
43
(set! from-selection FALSE))
45
(set! from-selection TRUE)
46
(set! active-selection (car (gimp-selection-save image)))))
47
(gimp-selection-layer-alpha drawable)
48
(set! active-selection (car (gimp-selection-save image)))
49
(set! from-selection FALSE)
52
(set! from-selection TRUE)
53
(set! active-selection (car (gimp-selection-save image)))
48
57
(gimp-edit-copy drawable)
50
59
(set! new-image (car (gimp-image-new selection-width
51
selection-height image-type)))
60
selection-height image-type)))
52
61
(set! new-draw (car (gimp-layer-new new-image
53
selection-width selection-height
54
draw-type "Selection" 100 NORMAL-MODE)))
62
selection-width selection-height
63
draw-type "Selection" 100 NORMAL-MODE)))
55
64
(gimp-image-add-layer new-image new-draw 0)
56
65
(gimp-drawable-fill new-draw BACKGROUND-FILL)
58
67
(let ((floating-sel (car (gimp-edit-paste new-draw FALSE))))
59
(gimp-floating-sel-anchor floating-sel))
68
(gimp-floating-sel-anchor floating-sel)
61
71
(gimp-image-undo-enable image)
62
72
(gimp-image-set-active-layer image drawable)
63
73
(gimp-display-new new-image)
64
74
(gimp-displays-flush)
68
80
(script-fu-register "script-fu-selection-to-image"
70
"Convert a selection to an image"
71
"Adrian Likins <adrian@gimp.org>"
76
SF-DRAWABLE "Drawable" 0)
78
(script-fu-menu-register "script-fu-selection-to-image"
79
_"<Image>/Script-Fu/Selection")
82
_"Convert a selection to an image"
83
"Adrian Likins <adrian@gimp.org>"
88
SF-DRAWABLE "Drawable" 0