; The GIMP -- an image manipulation program ; Copyright (C) 1995 Spencer Kimball and Peter Mattis ; ; Explode via Transparent Layer ; Copyright (c) 2000-2004 Matteo Nastasi aka mop ; nastasi@alternativeoutput.it ; matteo.nastasi@milug.org ; ; Take all layers with particular prefix, put disable everyone of this, ; and to loop for enable one to one, copy the image, crop and save it ; with the name of layer. ; ; ; 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. ; ; You should have received a copy of the GNU General Public License ; along with this program; if not, write to the Free Software ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. (define (script-fu-mop-im-explode-via-transplay img drw pref type path) ; disable undo (gimp-image-undo-disable img) ; number of char in prefix (set! char-num (string-length pref)) ; extract number and array of layer (set! layarray (gimp-image-get-layers img)) (set! nlay (car layarray)) (set! lay-arr (cadr layarray)) (set! ct 0) (set! i 0) (while (< i nlay) (set! curlay (aref lay-arr i)) (set! namelay (car (gimp-layer-get-name curlay))) (if (equal? (substring namelay 0 char-num) pref) (begin ; if layer start with pref dup image and save only this active (set! nw-img (car (gimp-channel-ops-duplicate img))) (set! nw-layarray (gimp-image-get-layers nw-img)) (set! nw-lay-arr (cadr nw-layarray)) (set! nw-ct 0) (set! nw-i 0) (while (< nw-i nlay) (set! nw-curlay (aref nw-lay-arr nw-i)) (if (= nw-i ct) (begin ; (gimp-image-set-active-layer nw-img nw-curlay) (gimp-layer-set-visible nw-curlay TRUE) (set! nw-w (car (gimp-drawable-width nw-curlay))) (set! nw-h (car (gimp-drawable-height nw-curlay))) (set! offsets (gimp-drawable-offsets nw-curlay)) (set! nw-x (car offsets)) (set! nw-y (cadr offsets)) ) (begin ; (gimp-image-set-active-layer nw-img nw-curlay) (set! nw-namelay (car (gimp-layer-get-name nw-curlay))) (if (equal? (substring nw-namelay 0 char-num) pref) (gimp-layer-set-visible nw-curlay FALSE) ) )) (set! nw-i (+ nw-i 1)) ) ; (gimp-image-merge-visible-layers nw-img 0) (gimp-crop nw-img nw-w nw-h nw-x nw-y) (set! fla (car (gimp-image-flatten nw-img))) ; (gimp-message (string-append namelay "." type)) (set! namelen (string-length namelay)) (set! namefile (string-append path "/" (substring namelay char-num namelen) "." type)) (gimp-file-save 1 nw-img fla namefile namefile) (gimp-image-delete nw-img) ; (gimp-display-new nw-img) (set! ct (+ ct 1)) ) ) (set! i (+ i 1)) ) ; end of while (gimp-image-undo-enable img) ) (script-fu-register "script-fu-mop-im-explode-via-transplay" "/Script-Fu/MOP/Explode via Trasp Lay" "Convert a selection to a new transparent layer" "Matteo Nastasi " "Matteo (aka mop) Nastasi" "09/11/2000" "RGB RGBA GRAY GRAYA" SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 SF-STRING "Prefix" "SUB_" SF-STRING "Extension" "pnm" SF-FILENAME "Path" ".")