first commit
[mop-gimp-scripts.git] / mop_im_select_to_trasp_lay.scm
1 ; The GIMP -- an image manipulation program
2 ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
4 ; Selection to Transparent Layer 
5 ; Copyright (c) 2000-2002 Matteo Nastasi aka MatOfPenguins aka mop
6 ; nastasi@alternativeoutput.it
7 ; matteo.nastasi@milug.org
8 ;
9 ;
10 ; This program derive from:
11 ;   Selection to Image
12 ;   Copyright (c) 1997 Adrian Likins
13 ;   aklikins@eos.ncsu.edu
14 ;
15 ; Takes the Current rectangular selection and put it as a new layer of image.
16 ;
17 ;
18 ; This program is free software; you can redistribute it and/or modify
19 ; it under the terms of the GNU General Public License as published by
20 ; the Free Software Foundation; either version 2 of the License, or
21 ; (at your option) any later version.
22
23 ; This program is distributed in the hope that it will be useful,
24 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
25 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26 ; GNU General Public License for more details.
27
28 ; You should have received a copy of the GNU General Public License
29 ; along with this program; if not, write to the Free Software
30 ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31
32
33 (define (script-fu-mop-im-select-to-trasplay image drawable name)
34   (let* ((selection-bounds 0) (select-offset-x 0) (select-offset-y 0)
35          (selection-width 0) (selection-height 0) (active-lay 0)
36          (new-draw 0)
37          (draw-type (car (gimp-drawable-type-with-alpha drawable)))
38          (image-type (car (gimp-image-base-type image))))
39
40     (set! selection-bounds (gimp-selection-bounds image))
41     (set! select-offset-x (cadr selection-bounds))
42     (set! select-offset-y (caddr selection-bounds))
43     (set! selection-width (- (cadr (cddr selection-bounds)) select-offset-x))
44     (set! selection-height (- (caddr (cddr selection-bounds)) select-offset-y))
45     (set! active-lay (car (gimp-image-get-active-layer image)))
46     
47     (gimp-undo-push-group-start image)
48     (if (= (car (gimp-selection-is-empty image)) TRUE)
49         (gimp-message "Selection empty")
50         (begin
51           (set! new-draw (car (gimp-layer-new image selection-width selection-height 1 name 100 NORMAL)))
52           (gimp-image-add-layer image new-draw 0)
53           (gimp-layer-set-offsets new-draw select-offset-x select-offset-y)
54           (gimp-edit-clear new-draw)
55           (gimp-image-set-active-layer image active-lay)
56           (gimp-displays-flush))
57         )
58     (gimp-undo-push-group-end image)
59     ))
60           
61 (script-fu-register "script-fu-mop-im-select-to-trasplay"
62                     "<Image>/Script-Fu/MOP/Select To Trasp Lay"
63                     "Convert a selection to a new transparent layer"
64                     "Matteo Nastasi <mnastasi@lycosmail.com>"
65                     "Matteo (Of Pinguins) Nastasi"
66                     "09/11/2000"
67                     "RGB RGBA GRAY GRAYA"
68                     SF-IMAGE "Image" 0
69                     SF-DRAWABLE "Drawable" 0
70                     SF-STRING "Name of layer" "transp-sel")
71
72
73