Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Export all layers to distinct files?

3,094 views
Skip to first unread message

Toby Newman

unread,
Oct 8, 2008, 5:00:01 PM10/8/08
to
Is there a command to save out all the component layers of a gimp file
into individual images?

--
-Toby
Add the word afiduluminag to the subject to circumvent my email filters.

Floyd L. Davidson

unread,
Oct 8, 2008, 6:08:26 PM10/8/08
to
Toby Newman <goo...@asktoby.com> wrote:
>Is there a command to save out all the component layers of a gimp file
>into individual images?

No, but that is relatively easy to do. It would also be
relatively easy to write a Script-Fu or Python script to
do it. The difficulty is most just working out conventions
like what to name the files produced...

Note that if saving all of your layers to work on later
is what you actually want, just save it to XCF format.
When you reload the XCF file, all of your layers will
still exist. (What does not exist is an edit history,
so you cannot undo the last edit made in order to revert
to something previous.)

To actually save each layer to a file, one method would
be to go to the "Layers" window and turn off visibility
of all layers except the one you want to save, then go
to the Image menu and select "Flatten image". You can
then save the image as you see it to whatever filename
you choose. After saving it, go to the "Edit" menu and
click on the "Undo" option which will reverse the "Image
flatten" command to restore the original multiple
layers. You can then change which layer is visible, and
repeat the process.

--
Floyd L. Davidson <http://www.apaflo.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) fl...@apaflo.com

Niels Giesen

unread,
Oct 10, 2008, 4:30:55 AM10/10/08
to
fl...@apaflo.com (Floyd L. Davidson) writes:

> To actually save each layer to a file, one method would
> be to go to the "Layers" window and turn off visibility
> of all layers except the one you want to save, then go
> to the Image menu and select "Flatten image".

This is unnecessary, simply go to the layers window, pick a layer
and drag it onto the toolbox. This will paste the layer as a new
image.

Or use something like the script below (yes, I had some time on my
hands...). It will save each layer to a png file; if the image is not
yet attached to a file, it will put the files in the ~/.gimp-n.n/tmp
directory. They are named after the master image and the layer name:

;; -*- mode: Gimp; -*-
(define (script-fu-save-layers-to-files image dont-ask display-images)
(let ((basename (car (gimp-image-get-filename image))))
(when (string=? basename "")
(set! basename (string-append
(car (gimp-temp-name ""))
(car (gimp-image-get-name 61)))))
(let loop ((layers (vector->list (cadr (gimp-image-get-layers image)))))
(unless (null? layers)
(gimp-edit-copy (car layers))
(let ((img (car (gimp-edit-paste-as-new)))
(new-name (string-append
basename
(car (gimp-drawable-get-name (car layers)))
".png")))
(file-png-save dont-ask
img
(aref (cadr (gimp-image-get-layers img)) 0)
new-name
new-name
TRUE 9 FALSE TRUE FALSE FALSE TRUE)
(if (= FALSE display-images)
;; clean up afterwards if we are not going to
;; display the images anyway:
(gimp-image-delete img)
(gimp-display-new img)))
(loop (cdr layers))))))

(script-fu-register "script-fu-save-layers-to-files"
_"Save all layers to a different file"
_"Saves all layers to separate .png files"
"Niels Giesen (niels....@gmail.com)"
"Niels Giesen"
"2008-10-10"
""
SF-IMAGE "Image" 1
SF-TOGGLE _"Don't ask options for each layer" TRUE
SF-TOGGLE _"Display images?" FALSE)

(script-fu-menu-register "script-fu-save-layers-to-files"
_"<Image>/Filters/Generic")

Save to ~/.gimp-n.n/scripts/script-fu-save-layers-to-files.scm

...though I am sure something like this must have been done before...

Regards,

Niels Giesen.

http://niels.kicks-ass.org
http://niels.kicks-ass.org/gimpmode/

Spamless

unread,
Oct 10, 2008, 10:22:15 AM10/10/08
to
On 2008-10-08, Toby Newman <goo...@asktoby.com> wrote:
> Is there a command to save out all the component layers of a gimp file
> into individual images?

Do you have the GAP plugin (Gimp Animation Plugin)?

This does animation using frames, separate images.
It also handes animations as in GIF, each frame a layer.

It can convert from an animation made up of layers to
separate frames/images.

Use

Video:Split Image to Frames

and each layer comes out as a separate file.

Michael Soibelman

unread,
Oct 10, 2008, 12:53:44 PM10/10/08
to
Niels Giesen wrote:

Tried the script. Simple three layer image with a 5x5 circle filled with
red, green and blue on separate layers. I got the following error
messages:


GIMP Message
Error while executing
(script-fu-save-layers-to-files 1 TRUE TRUE)

Error: Procedure execution of gimp-image-get-name failed on invalid input
arguments
Save all layers to a different file Message
Procedure 'gimp-image-get-name' has been called with an invalid ID for
argument 'image'. Most likely a plug-in is trying to work on an image that
doesn't exist any longer.

Using Gimp-2.4.7 on openSUSE-10.3

Niels Giesen

unread,
Oct 10, 2008, 4:19:00 PM10/10/08
to
Michael Soibelman <in-...@ether.net> writes:


> Tried the script. Simple three layer image with a 5x5 circle filled with
> red, green and blue on separate layers. I got the following error
> messages:
>
>
> GIMP Message
> Error while executing
> (script-fu-save-layers-to-files 1 TRUE TRUE)
>
> Error: Procedure execution of gimp-image-get-name failed on invalid input
> arguments
> Save all layers to a different file Message
> Procedure 'gimp-image-get-name' has been called with an invalid ID for
> argument 'image'. Most likely a plug-in is trying to work on an image that
> doesn't exist any longer.
>
> Using Gimp-2.4.7 on openSUSE-10.3
>

Ech, replace 61 with image in the script. So

(car (gimp-image-get-name 61)))))

becomes

(car (gimp-image-get-name image)))))

Good reminder to always try code with a clean program before
posting (image 61 was still lying around...). Sorry about that.


--
http://niels.kicks-ass.org

Michael Soibelman

unread,
Oct 11, 2008, 1:21:02 PM10/11/08
to
Niels Giesen wrote:

O.K. That worked. Now, for a nice improvement it would be nice if the
saved images would use the layer names as the saved images names. Somehow
Untitled-2.0, Untitled-3.0 & Untitled-4.0 doesn't seem to do it. My test
image has layers red, blue & green so red, blue & green would better
represent my choice. Any way you could modify this script to use the layer
names as the saved images names ???

Thanks for your effort. A little tweaking and voila'... Quite usefull.

Niels Giesen

unread,
Oct 11, 2008, 3:25:19 PM10/11/08
to
Michael Soibelman <in-...@ether.net> writes:

The script already saved the layers to a pretty long and ugly (but
unique, so that it is safe) name made out of the source image and the
layer name, so that is different. But apparently you do not see this
in the UI until you set it.

I modified the script so in the UI you'll see the layer name as the
image name. However when you save it, it will then save to a different
name, and hence to a different file.

What is your take on the correct approach?

Also note the difference between splitting an image that already has a
file association and an image that has not (such as a generated logo):
the first saves next to the source image, while the second puts it,
for lack of something better, in ~/.gimp-n.n/tmp/

If we'd let the script only split, not save, things would be easier.
How are you going to use it?

;; -*- mode: Gimp; -*-
(define (script-fu-save-layers-to-files image dont-ask display-images)
(let ((basename (car (gimp-image-get-filename image))))
(when (string=? basename "")
(set! basename (string-append
(car (gimp-temp-name ""))

(car (gimp-image-get-name image)))))


(let loop ((layers (vector->list (cadr (gimp-image-get-layers image)))))
(unless (null? layers)
(gimp-edit-copy (car layers))

(let* ((img (car (gimp-edit-paste-as-new)))
(layer-name (car (gimp-drawable-get-name (car layers))))
(new-name (string-append
basename
layer-name
".png")))
(gimp-image-set-filename img layer-name)

Michael Soibelman

unread,
Oct 11, 2008, 4:03:06 PM10/11/08
to
Niels Giesen wrote:

Don't sweat it bro' I'm busy today so I'll look at it later. Otherwise it
should be o.k... After I fiddle around with it I'll offer any feedback or
comments at that point.

Anyway, looks like you are pretty good with scripts for Gimp.... Which
reminds me of a plugin I'd like to see added to Gimp. The idea is this.
Create a plugin that keeps a list of all available plugins at the plugin
registry. You can check/uncheck any plugins to add/delete them from your
active plugins. All in alphabetic or 'group' order for easy
searching/selecting. This way you don't have to go to the web site,
download and then install.. This would probably be the most handy plugin
ever.. Think of it as the 'plugin for plugins' plugin.... (pfp ?)

Anyway, if you could do that I think you will become quite well liked by
Gimp users everywhere...or at least I'd appreciate it... I'll leave the
tough work to you if you think you can do it.. A little dash of wget and
some local repository structure and your on your way...


P.S. Just hoping as I've wished for such a thing for many years.. If you
could pull this off you'd be on your way to international stardom...

Thanks again for the original plugin. I'll be using it.

Niels Giesen

unread,
Oct 12, 2008, 2:53:52 AM10/12/08
to
Michael Soibelman <in-...@ether.net> writes:


> Don't sweat it bro' I'm busy today so I'll look at it later. Otherwise it
> should be o.k... After I fiddle around with it I'll offer any feedback or
> comments at that point.
>
> Anyway, looks like you are pretty good with scripts for Gimp.... Which
> reminds me of a plugin I'd like to see added to Gimp. The idea is this.
> Create a plugin that keeps a list of all available plugins at the plugin
> registry. You can check/uncheck any plugins to add/delete them from your
> active plugins. All in alphabetic or 'group' order for easy
> searching/selecting. This way you don't have to go to the web site,
> download and then install.. This would probably be the most handy plugin
> ever.. Think of it as the 'plugin for plugins' plugin.... (pfp ?)
>
> Anyway, if you could do that I think you will become quite well liked by
> Gimp users everywhere...or at least I'd appreciate it... I'll leave the
> tough work to you if you think you can do it.. A little dash of wget and
> some local repository structure and your on your way...

First of all, I have got better things to do, and the web interface
does not bother me that much, so no, I won't do it.

Now, as some random thoughts regarding your proposed plug-in:

"On your way", maybe, but:

The Scheme used in the Gimp is pretty dumbed down and has no access to
libgimp (although I can remember having read plans to give it access).
Merely the act of listing many checkboxes does not work correctly
(window decorations and buttons are gone, the latest do not even show
up, I guess that no-one ever has wanted to use so many options). In
other words: even if it could be done in Script-FU, it would be very
clunky.

This means such a thing would have to be scripted in Python or as a
stand-alone app in anyones favourite language. Hell, I guess you could
even do it in bash. You'd probably also want to have the features such
as tags present in the registry, meaning you'd have to have a decent
API to work with, otherwise it's scripting against HTML that might be
subject to change. I am not aware of such an API.

Also note that with something that would let users add plug-ins so
easily, quality control is a must. If only to ward against malicious
content. Which means constant human intervention. Are you willing to
take that upon you?

Anyway, I think such a project would basically mirror the registry
website, not add a lot more, and take quite some time to develop and
maintain. Though if it were present, I'd probably use it too.


> P.S. Just hoping as I've wished for such a thing for many years.. If you
> could pull this off you'd be on your way to international stardom...
>
> Thanks again for the original plugin. I'll be using it.

You're welcome.

david.f...@gmail.com

unread,
Dec 27, 2012, 1:08:56 AM12/27/12
to
Upgrade to GIMP 2.6. Upgrade to GIMP 2.6. Open your GIF in GIMP. Go to <Video><Split Image To Frames><then specify extension.png. or .jpg > note: GIMP will nominate destination for new images in same File Folder the original GIF came from>press Enter. That'll do it! Good luck

uncle808us

unread,
Jan 1, 2013, 8:46:23 PM1/1/13
to
In article <9d4fa6e5-25ac-4903...@googlegroups.com>,
There is a script for this I don't remember where I found it but I found
one by googling it."Layers to .png's" it took a while.

--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---

rowi...@gmail.com

unread,
Feb 28, 2013, 10:11:37 AM2/28/13
to
pues miren:
look:
http://www.trebol-a.com/2011/03/22/guardar-todas-las-capas-gimp

funcional en gimp2, pero exporta la imagen recortada, ¿alguien sabe, cómo exportar con el marco?
Message has been deleted

Spamless

unread,
Mar 1, 2013, 9:32:27 PM3/1/13
to
On 2008-10-08, Toby Newman <goo...@asktoby.com> wrote:
> Is there a command to save out all the component layers of a gimp file
> into individual images?

The gimp animation tool. In animation, gimp treats each layer as a frame.
Use the animation tool to take the image (each layer is treated as a frame)
and split into separate frames (that saves each frame/layer as a separate
file, useful, for example, in loading into other things, e.g. mencoder
if you choose to save the layers as pngs, to encode into an animation
of some type - if, it is indeed, an animation).
0 new messages