1 ; The GIMP -- an image manipulation program
2 ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
4 ; Explode via Transparent Layer NG
5 ; Copyright (c) 2000-2002 Matteo Nastasi aka MatOfPenguins aka mop
6 ; nastasi@alternativeoutput.it
7 ; matteo.nastasi@milug.org
9 ; Take all layers with particular prefix, put disable everyone of this,
10 ; and to loop for enable one to one, copy the image, crop and save it
11 ; with the name of layer.
14 ; This program is free software; you can redistribute it and/or modify
15 ; it under the terms of the GNU General Public License as published by
16 ; the Free Software Foundation; either version 2 of the License, or
17 ; (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.
24 ; You should have received a copy of the GNU General Public License
25 ; along with this program; if not, write to the Free Software
26 ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 (define (script-fu-mop-im-explode-via-trasplay-batch filename
32 (let* ((image 0) (drawable 0))
33 (set! image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
34 (set! drawable (car (gimp-image-get-active-layer image)))
35 (script-fu-mop-im-explode-via-transplay image drawable pref ext path)
36 (gimp-image-delete image)
39 (define (script-fu-mop-im-explode-via-transplay img drw pref type path)
41 (let* ((char-num 0) (layarray 0) (nlay 0) (lay-arr 0) (ct 0) (i 0)
42 (curlay 0) (namelay 0) (namelaylen 0) (name 0) (namelen 0)
43 (nw-img 0) (nw-layarray 0) (nw-lay-arr 0) (nw-ct 0) (nw-i 0)
44 (nw-curlay 0) (nw-namelay 0) (nw-w 0) (nw-h 0) (nw-x 0) (nw-y 0)
45 (offsets 0) (fla 0) (namefile 0))
46 (gimp-image-undo-freeze img)
47 ; number of char in prefix
48 (gimp-message (string-append "pref: " pref))
50 (set! char-num (string-length pref))
51 ; extract number and array of layer
52 (set! layarray (gimp-image-get-layers img))
53 (set! nlay (car layarray))
54 (set! lay-arr (cadr layarray))
59 ; (gimp-message "in while")
60 (set! curlay (aref lay-arr i))
61 (set! namelay (car (gimp-layer-get-name curlay)))
63 (if (and (>= (string-length namelay) char-num)
64 (equal? (substring namelay 0 char-num) pref))
66 ; (gimp-message (string-append "save layer: " namelay))
67 (set! namelaylen (string-length namelay))
68 (set! name (substring namelay char-num namelaylen))
69 (set! namelen (string-length name))
71 ; if layer start with pref dup image and save only this active
72 (set! nw-img (car (gimp-image-duplicate img)))
74 ; (set! nw-img2 (car (gimp-image-duplicate img)))
75 ; (set! fla2 (car (gimp-image-merge-visible-layers nw-img2 0)))
76 ; (set! namefile (string-append path "/" name "_orig." type))
77 ; (gimp-file-save 1 nw-img2 fla2 namefile namefile)
79 (set! nw-layarray (gimp-image-get-layers nw-img))
80 (set! nw-lay-arr (cadr nw-layarray))
85 ; (gimp-message "in while2")
87 (set! nw-curlay (aref nw-lay-arr nw-i))
90 ; (gimp-image-set-active-layer nw-img nw-curlay)
91 ; (gimp-message "begin if")
92 (set! nw-namelay (car (gimp-layer-get-name nw-curlay)))
93 ; (gimp-message (string-append "layer activated = nw-i: " nw-namelay (number->string nw-i)))
94 (gimp-layer-set-visible nw-curlay TRUE)
95 (set! nw-w (car (gimp-drawable-width nw-curlay)))
96 (set! nw-h (car (gimp-drawable-height nw-curlay)))
97 (set! offsets (gimp-drawable-offsets nw-curlay))
98 (set! nw-x (car offsets))
99 (set! nw-y (cadr offsets))
102 ; (gimp-image-set-active-layer nw-img nw-curlay)
103 (set! nw-namelay (car (gimp-layer-get-name nw-curlay)))
104 ; (gimp-message (string-append "begin else xx " nw-namelay))
105 (if (and (>= (string-length nw-namelay) char-num)
106 (equal? (substring nw-namelay 0 char-num) pref))
107 (gimp-layer-set-visible nw-curlay FALSE)
110 (if (and (>= (string-length nw-namelay) (string-length (string-append name "-")))
111 (equal? (substring nw-namelay 0 (+ namelen 1)) (string-append name "-")))
113 ; (gimp-message (string-append "layer activated: " nw-namelay))
115 (gimp-layer-set-visible nw-curlay TRUE)
119 ; (gimp-message "end else")
122 (set! nw-i (+ nw-i 1))
124 ; (gimp-message "out while2")
126 (gimp-crop nw-img nw-w nw-h nw-x nw-y)
127 (set! fla (car (gimp-image-merge-visible-layers nw-img 0)))
128 ; (set! fla (car (gimp-image-flatten nw-img)))
129 ; (gimp-message (string-append namelay "." type))
131 ; (set! namelen (string-length namelay))
132 ; (set! namefile (string-append path "/" (substring namelay
136 (set! namefile (string-append path "/" name "." type))
138 (gimp-file-save 1 nw-img fla namefile namefile)
139 ; (file-png-save2 1 nw-img fla namefile namefile 0 9 1 1 1 1 1 0 1)
140 ; (file-png-save2 1 nw-img fla namefile namefile 1 9 0 0 0 0 0 1 0)
141 (gimp-image-delete nw-img)
142 ; (gimp-display-new nw-img)
149 ; (gimp-message "the end")
152 (gimp-image-undo-thaw img)
156 (script-fu-register "script-fu-mop-im-explode-via-transplay"
157 "<Image>/Script-Fu/MOP/Explode via Trasp Lay"
158 "Convert a selection to a new transparent layer"
159 "Matteo Nastasi <nastasi@alternativeoutput.it>"
162 "RGB RGBA GRAY GRAYA"
164 SF-DRAWABLE "Drawable" 0
165 SF-STRING "Prefix" "SUB_"
166 SF-STRING "Extension" "png"
167 SF-DIRNAME "Path" ".")