It is currently Sat Aug 22, 2026 4:53 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Help with "Save All Layers" script, by saulgoode[SOLVED]
PostPosted: Tue Sep 20, 2016 1:27 am  (#1) 
Offline
Administrator
User avatar

Joined: Aug 10, 2012
Posts: 14165
Location: Native to NYC living in Arizona, Gimp 2.8 - 3.0, Win 11 PC.
I have this script,
written by saulgoode named sg-save-all-layers.scm.

The script saves all layers nicely,
but there's no way to change the location of where the files are saved.

As it stands,
the script saves the file to Gimp's Program bin folder.

I would like to be able to select another location to save the files to.


 
; 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.

;; Command is installed in "File->Save all layers..."
;;
;; A template string should be provided which fits the form: prefix~~~~.ext
;; where prefix is a character string (optionally null).
;;       ~~~~ represents the digits of the frame number, one ~ per digit
;;       ext is the filename extension (which also specifies the format)
;; the tildas are optional and four digits will be assumed if omitted.
;; an extension of .png is assumed if one is not provided
;; the period is significant, if PNG is not to be assumed
;;
;; A checkbox provides the option of using the layernames for the
;; filenames. The extension given in the template is used to determine
;; the file type. Animation settings (delay and frame disposal) are not
;; included as part of the filename.
;;
;; When saving to GIF files, the GIMP's default values are used to
;; convert to INDEXED mode (255 color palette, no dithering).
;; Note: this is done on a layer-by-layer basis, so more colors may result
;; than if the entire image were converted to INDEXED before saving.


(define (sg-save-all-layers orig-image drawable
                                    template
                                    rename?)
  (define (save-layer orig-image layer name)
    (let ((buffer (car (gimp-edit-named-copy layer "temp-copy"))))
      (let ((image (car (gimp-edit-named-paste-as-new buffer))))
        (gimp-buffer-delete buffer)
        (set! buffer (strbreakup name "."))
        (unless (> (length buffer) 1)
          (set! name (string-append name ".png")) )
        (when (and (not (= (car (gimp-image-base-type image)) INDEXED))
                   (string-ci=? (car (last (strbreakup name "."))) "gif"))
          (gimp-image-convert-indexed image
                                      NO-DITHER
                                      MAKE-PALETTE
                                      255
                                      FALSE
                                      FALSE
                                      "" ))
        (gimp-file-save RUN-NONINTERACTIVE
                        image
                        (car (gimp-image-get-active-layer image))
                        name
                        name )
        (gimp-image-delete image) )))
  (let* ((layers nil)
         (fullname "")
         (basename "")
         (layername "")
         (format "")
         (layerpos 1)
         (framenum "")
         (settings "")
         (default-extension "png")
         (extension "png")
         (orig-selection 0) )
    (gimp-image-undo-disable orig-image)
    (set! orig-selection (car (gimp-selection-save orig-image)))
    (gimp-selection-none orig-image)

    (set! extension (strbreakup template "."))
    (set! extension (if (> (length extension) 1)
                      (car (last extension))
                      default-extension))
    (when (= (string-length extension) 0)
      (set! default-extension "png"))
    (when (= rename? TRUE)
      (set! format (strbreakup template "~"))
      (if (> (length format) 1)
        (begin
          (set! basename (car format))
          (set! format (cdr format))
          (set! format (cons "" (butlast format)))
          (set! format (string-append "0" (unbreakupstr format "0"))) )
        (begin
          (set! basename (car (strbreakup template ".")))
          (set! format "0000") )))
    (set! layers (reverse (vector->list (cadr (gimp-image-get-layers orig-image)))))
    (while (pair? layers)
      (if (= rename? TRUE)
        (begin
          (set! framenum (number->string layerpos))
          (set! framenum (string-append
                (substring format 0 (- (string-length format)
                                       (string-length framenum))) framenum))
          (set! fullname (string-append basename framenum "." extension)) )
        (begin
          (set! fullname (car (strbreakup
                           (car (gimp-drawable-get-name (car layers))) "(")))
          (gimp-drawable-set-name (car layers) fullname)
          (set! fullname (car (gimp-drawable-get-name (car layers)))) ))
      (save-layer orig-image (car layers) fullname)
      (set! layers (cdr layers))
      (set! layerpos (+ layerpos 1))
      )
    (gimp-selection-load orig-selection)
    (gimp-image-remove-channel orig-image orig-selection)
    (gimp-image-undo-enable orig-image)
    )
  )

(script-fu-register "sg-save-all-layers"
"Save all layers..."
"Save each layer to a file."
"Saul Goode"
"Saul Goode"
"11/16/2008"
"*"
SF-IMAGE    "Image"    0
SF-DRAWABLE "Drawable" 0
SF-STRING "Name Template (~ replaced by layer position)" "frame_~~~~.png"
SF-TOGGLE "Rename (ex: 'frame__0001')" TRUE
)

(script-fu-menu-register "sg-save-all-layers"
                         "<Image>/File/")

_________________
Image
"A wise man learns more from a foolish question than a fool can learn from a wise answer"
Image


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Help with "Save All Layers" script, by saulgoode
PostPosted: Tue Sep 20, 2016 1:57 am  (#2) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
Try this one, with the directory option you'll have to choose an existing folder to put it in.
Attachment:
sg-save-all-layers.scm [5.37 KiB]
Downloaded 754 times

_________________
TinT


Top
 Post subject: Re: Help with "Save All Layers" script, by saulgoode
PostPosted: Tue Sep 20, 2016 2:18 am  (#3) 
Offline
Administrator
User avatar

Joined: Aug 10, 2012
Posts: 14165
Location: Native to NYC living in Arizona, Gimp 2.8 - 3.0, Win 11 PC.
trandoductin wrote:
Try this one, with the directory option you'll have to choose an existing folder to put it in.
Attachment:
sg-save-all-layers.scm

:wow
You're the Man T!
Thanks a bunch!
:jumpclap

_________________
Image
"A wise man learns more from a foolish question than a fool can learn from a wise answer"
Image


Top
 Post subject: Re: Help with "Save All Layers" script, by saulgoode[SOLVED]
PostPosted: Tue Sep 20, 2016 6:24 pm  (#4) 
Offline
GimpChat Member

Joined: May 12, 2015
Posts: 4693
I do not know coding, but I am amazed at how quickly Tran whips up an answer to a problem!


Top
 Post subject: Re: Help with "Save All Layers" script, by saulgoode[SOLVED]
PostPosted: Tue Sep 20, 2016 6:30 pm  (#5) 
Offline
Administrator
User avatar

Joined: Aug 10, 2012
Posts: 14165
Location: Native to NYC living in Arizona, Gimp 2.8 - 3.0, Win 11 PC.
Pat625 wrote:
I do not know coding, but I am amazed at how quickly Tran whips up an answer to a problem!

Yes I agree.
:clap

_________________
Image
"A wise man learns more from a foolish question than a fool can learn from a wise answer"
Image


Top
 Post subject: Re: Help with "Save All Layers" script, by saulgoode[SOLVED]
PostPosted: Tue Sep 20, 2016 6:31 pm  (#6) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
:hehe If you knew how to code then you won't be amazed anymore

_________________
TinT


Top
 Post subject: Re: Help with "Save All Layers" script, by saulgoode[SOLVED]
PostPosted: Sat Sep 29, 2018 11:22 am  (#7) 
Offline
GimpChat Member

Joined: Sep 29, 2018
Posts: 9
Hi!
Also impressed with coding speed)
I'm autolisp Autocad programmer, but GIMP's scheme is a bit complex to me, because I don't know GIMP API)

I've got a question - is there way to export all layers but with starting from some integer count of first layers, keeping them as modifier layers.
For example, to put vignette - making first layer with vignette, starting script, setting there "1 layer to skip from begining", export all layers with first layer above each.

Is it possible to modify script like this?


Top
 Post subject: Re: Help with "Save All Layers" script, by saulgoode[SOLVED]
PostPosted: Sat Sep 29, 2018 4:07 pm  (#8) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
I think there's some script that weave layers or combine them or something like that not sure where it is or what it's called maybe others will chime in.

_________________
TinT


Top
 Post subject: Re: Help with "Save All Layers" script, by saulgoode[SOLVED]
PostPosted: Wed Oct 03, 2018 3:02 pm  (#9) 
Offline
GimpChat Member

Joined: Sep 29, 2018
Posts: 9
trandoductin wrote:
I think there's some script that weave layers or combine them or something like that not sure where it is or what it's called maybe others will chime in.


Thank you.
But I'm interested if it is possible by script logics to order update to that functionality)


Top
 Post subject: Re: Help with "Save All Layers" script, by saulgoode[SOLVED]
PostPosted: Wed Oct 03, 2018 9:39 pm  (#10) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
Sure anything is possible with script.
It would have to be custom script since it's no longer just saving all layers but you want to put a layer over top of all the layers before saving them right?
Maybe you want just want another script that puts very top on every other layer and merge down them all...then use the Save All Layers script.

_________________
TinT


Top
 Post subject: Re: Help with "Save All Layers" script, by saulgoode[SOLVED]
PostPosted: Wed Oct 03, 2018 10:11 pm  (#11) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
Try this one...
Top layer on all layers Plug-in
After which point you can use this existing script to save all your layers.

_________________
TinT


Top
 Post subject: Re: Help with "Save All Layers" script, by saulgoode[SOLVED]
PostPosted: Tue Oct 09, 2018 5:20 pm  (#12) 
Offline
GimpChat Member

Joined: Sep 29, 2018
Posts: 9
That will fit the scope, but merging hundreds of layers will be more slowly, unless "Save all layers" is turning layers off one by one during save.
I don't know, maybe it invokes internal command "Save special layer" every time and giving adress of every special layer and run it by count of layers.

So I wandering how actually script's engine works, because can't read scheme lisp.


Top
 Post subject: Re: Help with "Save All Layers" script, by saulgoode[SOLVED]
PostPosted: Wed Oct 10, 2018 12:46 am  (#13) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
it's python. you can read python right?
oh you mean the save layers script yeah it's scheme.
any function in scheme is like in this format for example in C or python
you call a function as
myfunc(param1, param2);
in scheme it's
(myfunc param1 param2)
you can check out what function it's calling by looking inside GIMP>Help>Procedure browser.

_________________
TinT


Top
 Post subject: Re: Help with "Save All Layers" script, by saulgoode[SOLVED]
PostPosted: Wed Oct 10, 2018 2:29 am  (#14) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
@1D_inc: Two python scripts that do something close to what you want:

interleave-layers
ofn-export-layers

Both are here: https://sourceforge.net/projects/gimp-t ... s/scripts/

ofn-export-layers has its own documentation in the ZIP, interleave-layers is documented here:
http://gimp-tools.sourceforge.net/animationtools.shtml

_________________
Image


Top
 Post subject: Re: Help with "Save All Layers" script, by saulgoode[SOLVED]
PostPosted: Wed Oct 10, 2018 8:44 pm  (#15) 
Offline
GimpChat Member

Joined: Sep 29, 2018
Posts: 9
Aw, there is second page already, didn't noticed where my message has gone)

I've tried Top layer on all layers Plug-in, and it is awesome!
It does exactly what we need, except there is no count of how many first layers should be applied.
This count is useful for complex mulilayer effects application. Can it be added there?

Baically, as lisp coder I read scheme syntax better than python's, but some scheme operators are unknown to me, so python is more readable to me at the moment.
Also thank you for guide to gimp's procedure browser, it is very helpful)

@ofnuts
A very nice library! Interleave layers is a nice concept, but Top layer on all layers is much closer because of automatic reading mixing mode.


Top
 Post subject: Re: Help with "Save All Layers" script, by saulgoode[SOLVED]
PostPosted: Thu Oct 11, 2018 6:01 pm  (#16) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
try this comment animicule maybe that script does what you want by letting you set number of top layers
https://www.gimplearn.net/viewtopic.php ... 072#p21072

_________________
TinT


Top
 Post subject: Re: Help with "Save All Layers" script, by saulgoode[SOLVED]
PostPosted: Fri Oct 12, 2018 3:52 pm  (#17) 
Offline
GimpChat Member

Joined: Sep 29, 2018
Posts: 9
Wow, sept 2017)
This script has description of exactly what we need, but I can't say that it works - it seems like it was very early beta.

Your Top layer on All layers works just awesome, except it doesnot skips turned off layer and doesnot contain number of layers from start to onlay.
Can you add support of autoskipping turned off layers in your script?
That will make us at least survive with this routine, by setting apropriable layer as first, turning other mergeable off, and then running layers stored to merge succesively one by one with Top layer on All layers.

Or, maybe there is way to write both layer skipping and multylayer support, setting active layer and every layer above as mergeable layers, and then applying them one by one as Top layer on All layers to all layers under active, turning off mergeable layers that were proceed?

I just don't know how tricky it will be to write such thing)


Top
 Post subject: Re: Help with "Save All Layers" script, by saulgoode[SOLVED]
PostPosted: Fri Oct 12, 2018 7:08 pm  (#18) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4527
Location: Canada
If it doesn't, try contact animicule about it.

_________________
TinT


Top
 Post subject: Re: Help with "Save All Layers" script, by saulgoode[SOLVED]
PostPosted: Mon Oct 15, 2018 5:27 pm  (#19) 
Offline
GimpChat Member

Joined: Sep 29, 2018
Posts: 9
I've sent code and proposal to python developer, we will try to make such a thing)
Thank you very much for your assistance!


Top
 Post subject: Re: Help with "Save All Layers" script, by saulgoode[SOLVED]
PostPosted: Wed Oct 17, 2018 1:06 pm  (#20) 
Offline
GimpChat Member

Joined: Sep 29, 2018
Posts: 9
trandoductin wrote:
If it doesn't, try contact animicule about it.


Hi)
There is our solution of this tool - now it merges all visible layer stack before active layer to each visible lower than active.
Very useful^^
Can you post this solution in gimplearn and provide a permanent link in this tread?
https://www.dropbox.com/s/dlpw5go4xgvzr2a/1D_merge_compose_top_layers.py?dl=0


Top
Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group