You are here

Export Layers as PNG

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
Rate this item!

File->Export Layers->as PNG

Prompts for a folder to save PNG files. Pretty straightforward. *Requires* python!

Should work with 2.4.x through 2.8.x. Will NOT work with some 2.7.x versions and the 2.8 RC1! 2.7 users should move on to current git and 2.8 RC users should upgrade to current 2.8.

- toggle to flatten (remove transparency).
- toggle to save only visible layers
- now saves as filename + layername and special characters are removed
- toggle to remove layer offsets
- toggle to zealous crop each PNG before saving
- handle layer groups (introduced in GIMP 2.8)

NOTE: the registry added a .txt extension - you need to rename to file to just '' and make executable if you're on linux.

AttachmentSize KB
GIMP Version: 
Code License: 


Seems buggy - worked better after I made this change:
newlayer = tmp.merge_visible_layers(0)
pdb.file_png_save(tmp, newlayer, ...
instead of
pdb.file_png_save(tmp, tmp.layers[0], ...

Hi thanks for the plugin it works great, im using 2.8.4.

One area that needs some work however, in the option i can set visible layers only, but nothing about visible groups only.

I think this would be better as then we could simply hide the groups that we don't want to export, otherwise we have to hide possibly hundreds of layers.

In any case its just made my life a whole lot easier even as it stands, so thank you again

Works well, except the origin of the separate png files that were exported seems to be off.
Steps to reproduce:
* 1 xfc or psd file with multiple layers that are smaller than the image size.
* export layers -> as png
* flatten images NO, only visible layers, yes or no
* result: all layers have the wrong origin in their respective sub-pngs.
* you can see this by reopening the output png files in gimp.

The layer needs to have its offset explicitly set before being saved. This can be done by adding the below line to the script:

tmp.layers[0].set_offsets(0, 0) # ADD THIS LINE
pdb.file_png_save(tmp, tmp.layers[0], fullpath, filename, 0, 9, 1, 1, 1, 1, 1) # BEFORE THIS LINE

Thanks - I added a toggle for that in the plug-in.


Sorry - I meant to say:

TIFF + compression = (slightly) lossy
PNG + compression = lossless



PNG8 = lossy

PNG24+ = lossless

thanks you cr33dog


The plugin doesn't care about problematic characters for the file system given by the names of the layers. For example if you have a ":" character in the layer name the plugin creates only 1 empty file with a part of the layer name. I ran into this problem as i tested the standard globe animation plugin of Gimp, because it creates many layers with the ":" contained in the name.

The solution is to let the script remove / substitute all problematic characters. I did it by substituting this line:

        name = + ".png"

with this one (works well for windows):

        name = re.sub('([\\\\/:*?"<>|])', "_", + ".png"

and by adding this line on top of the script:

import re

The script looks after that like this:

#!/usr/bin/env python
# Author: Chris Mohler
# Copyright 2009 Chris Mohler
# License: GPL v3
# Version 0.3
# GIMP plugin to export layers as PNGs
# Fixed Version BY BPhoenix

from gimpfu import *
import os
import re

gettext.install("gimp20-python", gimp.locale_directory, unicode=True)

def export_layers(img, drw, path, flatten=False):
	reg = re.compile
	dupe = img.duplicate()
	for layer in dupe.layers:
		layer.visible = 0
	for layer in dupe.layers:
		layer.visible = 1
		name = re.sub('([\\\\/:*?"<>|])', "_", + ".png"
		fullpath = os.path.join(path, name);
		tmp = dupe.duplicate()
		if (flatten):
		pdb.file_png_save(tmp, tmp.layers[0], fullpath, name, 0, 9, 1, 1, 1, 1, 1)

	blurb=("Export Layers as PNG"),
	help=("Export all layers as individual PNG files."),
	author=("Chris Mohler"),
	copyright=("Chris Mohler"),
	label=("as _PNG"),
	(PF_IMAGE, "img", "Image", None),
	(PF_DRAWABLE, "drw", "Drawable", None),
	(PF_DIRNAME, "path", "Save PNGs here", os.getcwd()),
	(PF_BOOL, "flatten", "Flatten Images?", False),
	menu=("/File/E_xport Layers"), 
	domain=("gimp20-python", gimp.locale_directory)


And at least: Thank you for this plugin. Now i can easily create APNGs with the APNG Anime Maker.

It's a pitty, that the APNG Plugin on this site doesn't really work, that Gimp hasn't a build in filter for this and that the MNG Plugin is broken too...

the apng plugin for me works well


Subscribe to Comments for "Export Layers as PNG"