first commit
authorMatteo Nastasi <nastasi@alternativeoutput.it>
Sat, 14 Aug 2010 13:10:18 +0000 (15:10 +0200)
committerMatteo Nastasi <nastasi@alternativeoutput.it>
Sat, 14 Aug 2010 13:10:18 +0000 (15:10 +0200)
mop_im_explode_via_trasp_lay.scm [new file with mode: 0755]
mop_im_select_to_trasp_lay.scm [new file with mode: 0755]

diff --git a/mop_im_explode_via_trasp_lay.scm b/mop_im_explode_via_trasp_lay.scm
new file mode 100755 (executable)
index 0000000..53ac25e
--- /dev/null
@@ -0,0 +1,170 @@
+; The GIMP -- an image manipulation program
+; Copyright (C) 1995 Spencer Kimball and Peter Mattis
+; 
+; Explode via Transparent Layer NG
+; Copyright (c) 2000-2002 Matteo Nastasi aka MatOfPenguins 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-trasplay-batch filename
+                              pref
+                              ext
+                              path)
+   (let* ((image 0) (drawable 0))
+     (set! image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
+     (set! drawable (car (gimp-image-get-active-layer image)))
+     (script-fu-mop-im-explode-via-transplay image drawable pref ext path)
+     (gimp-image-delete image)
+     (gimp-quit 0) ))
+
+(define (script-fu-mop-im-explode-via-transplay img drw pref type path)
+; disable undo
+  (let* ((char-num 0) (layarray 0) (nlay 0) (lay-arr 0) (ct 0) (i 0)
+         (curlay 0) (namelay 0) (namelaylen 0) (name 0) (namelen 0)
+         (nw-img 0) (nw-layarray 0) (nw-lay-arr 0) (nw-ct 0) (nw-i 0)
+         (nw-curlay 0) (nw-namelay 0) (nw-w 0) (nw-h 0) (nw-x 0) (nw-y 0)
+         (offsets 0) (fla 0) (namefile 0)) 
+    (gimp-image-undo-freeze img)
+                                        ; number of char in prefix
+    (gimp-message (string-append "pref: " pref))
+    
+    (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) 
+                                        ;         (gimp-message "in while")
+           (set! curlay (aref lay-arr i))
+           (set! namelay (car (gimp-layer-get-name curlay)))
+           
+           (if (and (>= (string-length namelay) char-num)
+                    (equal? (substring namelay 0 char-num) pref))
+               (begin
+                                        ;               (gimp-message (string-append "save layer: " namelay))
+                 (set! namelaylen (string-length namelay))
+                 (set! name (substring namelay char-num namelaylen))
+                 (set! namelen (string-length name))
+                 
+                                        ; if layer start with pref dup image and save only this active
+                 (set! nw-img (car (gimp-image-duplicate img)))
+                 
+                                        ;             (set! nw-img2 (car (gimp-image-duplicate img)))
+                                        ;             (set! fla2 (car (gimp-image-merge-visible-layers nw-img2 0)))
+                                        ;             (set! namefile (string-append path "/" name "_orig." type))
+                                        ;             (gimp-file-save 1 nw-img2 fla2 namefile namefile)
+                 
+                 (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)
+                                        ;                      (gimp-message "in while2")
+                        
+                        (set! nw-curlay (aref nw-lay-arr nw-i))
+                        (if (= nw-i i)
+                            (begin
+                                        ;                          (gimp-image-set-active-layer nw-img nw-curlay)
+                                        ;                            (gimp-message "begin if")
+                              (set! nw-namelay (car (gimp-layer-get-name nw-curlay)))
+                                        ;                            (gimp-message (string-append "layer activated = nw-i: " nw-namelay (number->string nw-i)))
+                              (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)))
+                                        ;                            (gimp-message (string-append "begin else xx " nw-namelay))
+                              (if (and (>= (string-length nw-namelay) char-num)
+                                       (equal? (substring nw-namelay 0 char-num) pref))
+                                  (gimp-layer-set-visible nw-curlay FALSE)
+                                  )
+                              
+                              (if (and (>= (string-length nw-namelay) (string-length (string-append name "-")))
+                                       (equal? (substring nw-namelay 0 (+ namelen 1)) (string-append name "-")))
+                                  (begin
+                                        ;                                  (gimp-message (string-append "layer activated: " nw-namelay))
+                                    
+                                    (gimp-layer-set-visible nw-curlay TRUE)
+                                    )
+                                  )
+                              
+                                        ;                            (gimp-message "end else")
+                              
+                              ))
+                        (set! nw-i (+ nw-i 1))
+                        )
+                                        ;               (gimp-message "out while2")
+                 
+                 (gimp-crop nw-img nw-w nw-h nw-x nw-y)
+                 (set! fla (car (gimp-image-merge-visible-layers nw-img 0)))
+                                        ; (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))
+                 
+                 (set! namefile (string-append path "/" name "." type))
+                 
+                 (gimp-file-save 1 nw-img fla namefile namefile)
+                                        ; (file-png-save2 1 nw-img fla namefile namefile 0 9 1 1 1 1 1 0 1)
+                                        ; (file-png-save2 1 nw-img fla namefile namefile 1 9 0 0 0 0 0 1 0)
+                 (gimp-image-delete nw-img)
+                                        ; (gimp-display-new nw-img)
+                 (set! ct (+ ct 1))
+                 )
+               )
+           (set! i (+ i 1))
+           ) ; end of while
+    
+                                        ;  (gimp-message "the end")
+    
+    
+    (gimp-image-undo-thaw img)
+    )
+  )
+
+  (script-fu-register "script-fu-mop-im-explode-via-transplay"
+                      "<Image>/Script-Fu/MOP/Explode via Trasp Lay"
+                      "Convert a selection to a new transparent layer"
+                   "Matteo Nastasi <nastasi@alternativeoutput.it>"
+                   "Matteo Nastasi"
+                   "09/11/2000"
+                   "RGB RGBA GRAY GRAYA"
+                   SF-IMAGE "Image" 0
+                   SF-DRAWABLE "Drawable" 0
+                    SF-STRING "Prefix" "SUB_"
+                   SF-STRING "Extension" "png"
+                    SF-DIRNAME "Path"       ".")
+
+
+
diff --git a/mop_im_select_to_trasp_lay.scm b/mop_im_select_to_trasp_lay.scm
new file mode 100755 (executable)
index 0000000..d4f2cea
--- /dev/null
@@ -0,0 +1,73 @@
+; The GIMP -- an image manipulation program
+; Copyright (C) 1995 Spencer Kimball and Peter Mattis
+; 
+; Selection to Transparent Layer 
+; Copyright (c) 2000-2002 Matteo Nastasi aka MatOfPenguins aka mop
+; nastasi@alternativeoutput.it
+; matteo.nastasi@milug.org
+;
+;
+; This program derive from:
+;   Selection to Image
+;   Copyright (c) 1997 Adrian Likins
+;   aklikins@eos.ncsu.edu
+;
+; Takes the Current rectangular selection and put it as a new layer of image.
+;
+;
+; 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-select-to-trasplay image drawable name)
+  (let* ((selection-bounds 0) (select-offset-x 0) (select-offset-y 0)
+         (selection-width 0) (selection-height 0) (active-lay 0)
+         (new-draw 0)
+        (draw-type (car (gimp-drawable-type-with-alpha drawable)))
+        (image-type (car (gimp-image-base-type image))))
+
+    (set! selection-bounds (gimp-selection-bounds image))
+    (set! select-offset-x (cadr selection-bounds))
+    (set! select-offset-y (caddr selection-bounds))
+    (set! selection-width (- (cadr (cddr selection-bounds)) select-offset-x))
+    (set! selection-height (- (caddr (cddr selection-bounds)) select-offset-y))
+    (set! active-lay (car (gimp-image-get-active-layer image)))
+    
+    (gimp-undo-push-group-start image)
+    (if (= (car (gimp-selection-is-empty image)) TRUE)
+       (gimp-message "Selection empty")
+       (begin
+         (set! new-draw (car (gimp-layer-new image selection-width selection-height 1 name 100 NORMAL)))
+          (gimp-image-add-layer image new-draw 0)
+         (gimp-layer-set-offsets new-draw select-offset-x select-offset-y)
+          (gimp-edit-clear new-draw)
+          (gimp-image-set-active-layer image active-lay)
+          (gimp-displays-flush))
+       )
+    (gimp-undo-push-group-end image)
+    ))
+         
+(script-fu-register "script-fu-mop-im-select-to-trasplay"
+                   "<Image>/Script-Fu/MOP/Select To Trasp Lay"
+                   "Convert a selection to a new transparent layer"
+                   "Matteo Nastasi <mnastasi@lycosmail.com>"
+                   "Matteo (Of Pinguins) Nastasi"
+                   "09/11/2000"
+                   "RGB RGBA GRAY GRAYA"
+                   SF-IMAGE "Image" 0
+                   SF-DRAWABLE "Drawable" 0
+                    SF-STRING "Name of layer" "transp-sel")
+
+
+