64

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.

  • Parto please consider accepting the answer by @ThorSummoner askubuntu.com/a/749561/453746 as it seems to be a much better solution for new people finding this answer today without installing a plugin. – Jeff Puckett Sep 28 '19 at 4:23
43

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.

| improve this answer | |
  • 2
    This was the easiest. Extract the file, copy the .py file to your ~/.gimp-2.8/plug-ins folder, make it executable, restart GIMP. – Parto Jun 20 '14 at 12:27
  • Doesn't work in GIMP 2.6 btw. – installero Sep 6 '14 at 10:44
  • 2
    This is also availabe at GitHub: github.com/khalim19/gimp-plugin-export-layers – moi Aug 24 '16 at 8:30
  • the installation instructions for this plugin are stupid. :P Just install please, I don't care about directories. – ether_joe Jul 21 '18 at 18:17
  • Agreed that the installed (for linux) is rough; this is the command I needed to use to make it work with an AppImage GIMP install: ./export_layers-3.2.1-linux.run --target /home/myname/.config/GIMP-AppImage/2.10/plug-ins/ -- -g /path/to/gimp-git-2.10.5-20180719.glibc2.15-x86_64.AppImage -i /home/myname/.config/GIMP-AppImage/2.10/plug-ins/ – user272901 Aug 21 '18 at 5:13
96

If PNG is an acceptable output format, one option is to export it as Open Raster (.ora), an open specification for layered-image files.

  1. Export Image as Open Raster (.ora)

    File -> Export As ...

    myfile.ora

  2. Open myfile.ora as an archive, with a program like file-roller or 7zip.

    On Ubuntu:

    $ file-roller myfile.ora
    
    $ # note, later version of file-roller on ubuntu hard-code file suffixes, 
      # and refuse to open ".ora" files, work around by renaming the file to ".zip"
    $ ln -s myfile.ora myfile.ora.zip
    $ file-roller myfile.ora.zip
    

    alternatively

    $ unzip myfile.ora
    

    All your layers will be png images under /data, Extract them and use at will.

| improve this answer | |
  • 9
    this was awesome, thanks- I think this is the best solution. Nothing to install and very fast. I just did it with GIMP with a PSD. – LowFieldTheory Oct 11 '16 at 13:11
  • 1
    This exported a flattened image for me :( – Petah Nov 20 '16 at 21:59
  • 1
    Looks like ORA support was dropped in 2.10. :( – spacer GIF Aug 1 '19 at 20:10
  • 1
    @michael yikes, I'd guess the metadata is there in the ora somewhere, might be easy thing to script, at that rate I'm not sure why or what it takes to write a gimp export extension to do the right thing the first place – ThorSummoner Aug 26 '19 at 1:26
  • 1
    I noticed that recent Ubuntu distributions, file-roller might not be happy about opening an ora file, if this is troubling you, adding a .zip to the end of the file name may help convice your given ziptools to extract it – ThorSummoner Apr 7 at 2:57
7

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.

| improve this answer | |
  • 3
    Note: GIFs only support 256 colour palettes, so it would not be possible to do 24-bit PNGs this way. – thomasrutter Mar 24 '16 at 5:34
  • Furthermore, for large images convert takes ages while unziping an ORA file is almost instant. Good idea, though. – Skippy le Grand Gourou Dec 16 '18 at 21:27
6

Certainly, this work for the plugin Export Layers to File.

Features:

  • Manipulate the layers in layer group.
  • Export texts, patterns and layer filters.
  • Prefix name for the image files has to be given.
  • Export only in jpg, png, bmp formats but the required formats can be added easily.
| improve this answer | |
5

First of all you don't need any plugin. Even you don't need to crop anything. Few simple steps.

  1. Select a layer. To do that just click on that particular layer.
  2. Copy the layer to a clipboard using Ctrl+C
  3. Now create new image using Ctrl+Shift+V

That's it. Now you can simply export that layer to any format.

  1. Use Shift+Ctrl+E
| improve this answer | |
  • If you only wanted specific layers, then this is the better way to go... – Murshid Ahmed Jul 10 '19 at 18:20
  • Also, if you only wanted two or three layers. Not so great if you find yourself (as I did yesterday) wanting to export each and every one of the 79 frames in an animated gif. – FeRD Jul 31 at 21:25
3

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

| improve this answer | |
1

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.

| improve this answer | |
0

The best thing about ThorSummoner's answer, as it turns out, 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:

# If you have multiple images open, you may need to adjust
img = gimp.image_list()[0]

savefn = gimp.pdb['file-png-save-defaults']

for lay in img.layers:
    # Even if your layer names contain spaces, not a problem
    outname = lay.name + ".png"
    savefn(img, lay, "./"+outname, outname)
    
    # type an extra newline to exit the indented block

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 ran GIMP from.

If any of your layer names are the same, that is a problem, because this will happily overwrite any previously-written files. Caveat GIMPtor.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.