I have come to a situation where I have an image in Gimp with multiple layers. Now, I want to export every single layer as an individual image (PNG format preferably) automatically to a folder somewhere.
Is this possible?
The long method: Hide all layers except one, crop the section you want, export image. Hide saved layer, unhide another one, crop section, export. Repeat. Kinda cumbersome for an image with about 20 layers.
If PNG is an acceptable output format, one option is to export it as Open Raster (.ora), an open specification for layered-image files.
Export Image as Open Raster (.ora)
File -> Export As ...
myfile.ora
Open
myfile.ora
as an archive, with a program likefile-roller
or7zip
.On Ubuntu:
alternatively
All your layers will be png images under
/data
, Extract them and use at will.You may try also this plugin, Export Layers. I've tested it with png format and it worked. You just select the folder and the format and you get all the layers there, each one in its own file.
First of all you don't need any plugin. Even you don't need to crop anything. Few simple steps.
That's it. Now you can simply export that layer to any format.
One could export the image as an animated GIF. This will save each layer as a separate frame in the GIF.
Then, the ImageMagick command
convert -coalesce ./myfile.gif outfile%05d.png
will extract the frames as PNG images.Certainly, this work for the plugin Export Layers to File.
Features:
I think you can try to find something with
ImageMagick
:apt-get install imagemagick
. It seems to be able to handle XCF format and you can export a layer in png using a [N] in the command, where N is the level of your layer.Source : http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=17603
ImageMagick Read Mods : http://www.imagemagick.org/Usage/files/#read_mods
The best thing about ThorSummoner's answer is that it called attention to the OpenRaster export plugin, which as it turns out lives in the file
file-openraster.py
in the GIMP installation.By reading its code (and with some assistance from the built-in procedure browser), I was able to determine that the layers of a GIMP XCF can be saved to individual PNGs by going to Filters > Python-fu > Console in the interface, and entering the following into the built-in Python interpreter:
You'll see the progress meter in the image window's status bar start whipping through all of your layers, writing each one to a PNG file of the same name, in whatever directory you specified as
outpath
. (Which must already exist, otherwise add anos.makedirs(outpath, exist_ok=True)
before the loop.)If any of your layer names are the same, that is a problem, because this will happily overwrite any previously-written files. Caveat GIMPtor.
Edit: If you do have same-named layers, you could easily ignore the names and instead write out the layers in numbered files. Just replace the final loop above with something like:
That'll write the layers into PNG files named "Layer 000.png" through "Layer 999.png" (or however many layers are present, if fewer than 1000).
If the Gimp's version of Python doesn't support f-strings (Python 3.6+), this is exactly equivalent:
I was doing the same thing and trying to download the plugins mentioned in the answers. As the Gimp website is currently down, I could not get the plugins and I had to find another solution.
What I ended up doing was use the screenshot software Shutter, which allows you to select a region of the screen and then you can repeat the same screenshot of that region with just 1 click. So it becomes a 2-click per layer operation: hide layer, screenshot, hide next layer, screenshot, ...
Much faster than anything else I could come up with, and takes less than a minute for 20 layers. You may lose image quality although in my case it was not a problem.
Many years later, GIMP has removed the functionality from the accepted solution and some of the other code solutions have succumbed to code rot (I'm unable to run the GIMP exporter with Python3).
As this is one of the first hits from Google when asking how to export layers from GIMP to their own
PNG
files, I feel duty bound to provide an updated answer.I'm using GIMP 2.10.18.
Here is one solution that worked for me:
XCF
file as aPDF
(File -> Export as
) with the following in mind:Layers as pages (bottom layers first)
Apply layer masks before saving
Convert bitmaps to vector graphics where possible
Omit hidden layers and layers with zero opacity
pdftoppm
to export asPNG
files.For example, if you were to export the
XCF
file as the fileexported_layers.pdf
, the following will create each layer as it's ownPNG
image with the prefixout_
(e.g.out_01.png
,out_01.png
etc.):The
-r
option is the resolution and presumably this should match whatever default GIMP is set when exporting toPDF
files. I found 300 kept the resolution in the layers of my originalXCF
file but your mileage may vary.On Ubuntu, on can install
pdftoppm
by issuing:Export all frames from Gimp as MNG, then use ImageMagick for separating them to PNGs.
ImageMagick extends each file name with numbers (if you don't format the string) like "frame-1.png" and so on.