Export Layers as PNG

File->Export Layers->

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

Tested in 2.6.1 on linux and 2.6.6 on XP.

Updated with a toggle to flatten (remove transparency).

NOTE: the registry added a .txt extension - you need to rename to file to just 'export_layers-0.3.py'.

AttachmentSize
export_layers-0.3.py1.25 KB
0
Average: 5 (1 vote)

Comments

add file name to saved pngs

When the scripts saves the layers, I would like it to automatically append the file name to the saved pngs, cause I want to know which file they came from. I was looking at the script and it seems it would be on line 20, where it tells gimp what to name the layers. How should I change it?

Change line 20 to

Change line 20 to read:
name = img.name + layer.name + ".png"

Trouble using script

I have a windows icon file I am working with. I open it with gimp and the various sizes come up as layers. I want to save each layer as as a separate image. When I install this script, I only get the menu option "Open as layers", so I use that to open the image. It opens the image as a multi-layered image just as it does by normally opening it. I never get a menu option to export the layers. I am using Gimp 2.6.8 on Ubuntu.

"File->Open as Layers" is

"File->Open as Layers" is built into GIMP. "File->Export Layers->as PNG" is provided by this plug-in and ends up at the very bottom of the File menu. If the menu item is not there, make sure the plug-in file is in the right directory and executable (chmod +x or right-click and check permissions).

I've discovered my problem.

I've discovered my problem. I don't know how to install python plugins. So far I've been searching the documentation and I've found nothing.

In linux, plug-ins go into:

In linux, plug-ins go into: /home/USERNAME/.gimp-2.6/plug-ins/
(replace USERNAME with your own user name)

If the file is named like plugin_name.py.txt, then remove the .txt extension so it's named plugin_name.py

The file must be executable. Either do 'chmod +x plugin_name.py' in a terminal or right-click the file, select 'properties', then check the box for 'Execute'.

A little more info here: http://en.wikibooks.org/wiki/GIMP/Installing_Plugins#GNU.2FLinux

HTH,
Chris

Hello Cr33dog, I try your

Hello Cr33dog,
I try your plugin and it works.

I want to make CMYK separation for silkscreen print. I need a tool to save the four layers generated by separate+ because gutenprint can't print the layers one by one.

Even if it work wonderfully I've got a trouble with your plugin : the fact that it save the layers to PNG format (made for web not for print).

What part of the code could I change to save layers in another format(Tiff)?

Tia

PNG is not indexed

PNG is a lossless format, and is more suitable for printing than the TIFF format. (TIFF with compression causes slight information loss).

So again - PNG is not just "made for web". Did you have any specific problem printing the PNG file(s)?

No trouble for using the

No trouble for using the script and printing the PNG
Thank again for it and your prompt answers

close to " register"

To save as tiff instead then png I would change this line that is just close to the register block

"pdb.file_png_save(tmp, tmp.layers[0], fullpath, name, 0, 9, 1, 1, 1, 1, 1)"
just replace at beginning "pdb,file-png-save" with "pdb,file_tiff_save"

I didn't tested

How do I use the plug-in

I got Python installed and working with GIMP. I have the plug-in in the right folder. So now what? I opened an image as layers. How do I save a single layer?

It's designed to export all

It's designed to export all layers as PNG files to the specified directory. Have you tried running the plugin yet?

I opened my image as layers.

I opened my image as layers. I clicked on python-fu which brings up python console. I found the plug-in selected it and clicked apply. That put the plug-in into the console. Now what? It looks that I should click on save but what am I saving? I tried saving the image but I don't get any kind of prompt.

Thank you for your time and patience.

It should show up as

It should show up as File->Export Layers->as PNG.

This is what is in the

This is what is in the console window

GIMP 2.6.8 Python Console
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)]
>>> pdb.python_fu_export_layers(img, drw, path, flatten)

From the main menu of GIMP:

From the main menu of GIMP: File ->Export Layers ->as PNG.

Do not mess with the Python-Fu console just yet. That's for scripting on the fly - probably not what you are looking for.

Found the plug-in

I found the plug-in finally. So I opened my image as layers. Click on file - export as layers as png. All it did was same the image as save the whole image as background.png. Apparently there is only 1 layer to the image. I am totally confused. What I need to do is separate the layers/channels so I can put them into Sims 3 "Create a Pattern Tool so they will be recolorable in the game.

All this plug-in does is save

All this plug-in does is save each individual layer of an image as an PNG file. It only makes sense to use the plug-in on an image with two or more layers (I wrote it with having quite a lot of layers in mind, as a time saver).

I have no idea what you need to do to get your image(s) into the game. Maybe there's a Sims forum somewhere where you can ask?

All I am trying to do is get

All I am trying to do is get the individual layers saved and it's not working for me. So must be doing something wrong with the plug-in. These are the steps I take on more time.

1. Open image as layers. (That gives me 3 channels)
2. Click File - Export Layers
3. Save

All that happens is it saves the image as background.

Is this what is supposed to happen?

Channels are not layers. How

Channels are not layers. How many layers does your image have? (hint: press 'CTRL+L' to raise the layers dialog).

Perhaps you need to back up a bit and explain exactly what it is you're trying to do. It sounds like you are trying to save RGB channels to individual files. If so:

1. File ->Open (not Open as Layers)
2. Color->Components->Decompose (select RGB and leave 'decompose to layers' checked)
3. A new image will be created with three layers, select this image.
4. File->Export Layers->as PNG

If not, explain what you're after. You also might consider posting on the forum on this site instead of here - I doubt very many people are subscribed to comments on this plug-in.

Also - open as layers is meant to add an image to an already open one - as a new layer. It does not take a flat image and magically create new layers ;)

Thank you

It IS the channels I am trying to save. You have given me the information I need. Sorry to be so slow.

No problem. If you'd to buy

No problem. If you'd to buy me a cup of coffee, my pp address is cr33dog AT gmail DOT com :) If not, no worries - most if not all of my plugins are really just for fun or (my own) learning.

How do I get this plugin into Gimp

I downloaded and installed python, downloaded export_layers-0.3.py which turned out to be a txt file. I renamed it to give the .py extension. Now what do I do? I can't find a folder for plugins. I am dyslexic and have trouble with reading complicated instructions. If you could do a step by step (baby steps) it would be very helpful.

Thank you for your time.

Do you have python support?

Do you have the menu item Filters->Python-Fu?

If so, open GIMP preferences.
Select Folders->Plug-ins, note the plug-in directories.
In your OS, browse to the plug-in folder in your home directory (from above step).
Place .py file inside.
Restart GIMP.

If not, you need python support. I found this tutorial (I assume you're using Windows):
http://www.gimpusers.com/tutorials/install-python-for-gimp-2-6-windows.html

HTH,
Chris

I am working with Windows

I am working with Windows Vista 64 bit. I have already tried the tutorial. I downloaded the only version of pycairo I could find. It is 1.8.6 when I try to install it I get a message that "Python version 2.6 which required, which was not found in the registry. I had Python 2.6.5 installed. pycairo was made for 2.6.4
So I uninstalled Python 2.6.5 and installed the older version. I still get the same message. Is there a newer version of pycairo?

You should probably keep

You should probably keep using Python 2.6.5.

Try using the older version of pycairo though:
http://ftp.gnome.org/pub/GNOME/binaries/win32/pycairo/1.4/pycairo-1.4.12...

(from the link found on http://gimp-win.sourceforge.net/faq.html)

Depends on what OS you use...

First and foremost, is Python showing up on your GIMP menu?

Windows OS, (Vista and Win 7), the plug-ins folder is found in Users/Username/.gimp-2.6/plug-ins
Win XP - it's found under Documents and Settings/Username/.gimp-2.6/plug-ins
Linux (Ubuntu) - home/username/.gimp-2.6/plug-ins

If you have installed the .py file in the appropriate folder, as indicated above, and Python is showing on your GIMP menu, all you need to do is restart GIMP.

Got Python Support

I got Python working with Gimp now. I put the plug-in in the plug-in folder. So how do I use it? I opened my image with "open as layers". How do I select the layer I want to save?

python does not show up in

python does not show up in GIMP. My problem now is getting GIMP and Python working together.

Awesome script

Works perfect. Just one thing, how can I make it to save the png file with transparency?

I gave the latest plugin a

I gave the latest plugin a toggle button. Set 'Flatten Image' to 'Yes' to remove alpha/transparency or 'No' (the default) to preserve alpha/transparency.

Sweet! Thanks cr33dog.

Long time no see. Thanks for the update. :)

Good to be back. Though I

Good to be back. Though I don't have much time for free projects these days :( Buy hey, this update was like two lines and I probably should've added that option right from the start.

And it's nice to see we have notifications now - I often forget to log in and check for new messages.

When you get the prompt

When saving, (providing your layers have alpha channels) un-tick the save background color on the menu options.

works as advertised

This works perfectly in GIMP 2.6.7 on Ubuntu 9.10. Just drag to your plug-ins folder (probably ~/.gimp-2.6/plug-ins/) and then at the command line run chmod +x ~/.gimp-2.6/plug-ins/*.py and restart GIMP.

Not working on 2.6.7

I've tried using this in Gimp 2.6.7. and no options come up. There's not even a menu entry

i guess you use windows

..and that you do not have the gimp python module installed

and install it may be a bit complex see

http://www.registry.gimp.org/node/3916

if you want to save layers

if you want to save layers with alpha channel you only need to comment tmp.flatten(). The code looks like: for layer in dupe.layers: layer.visible = 1 name = layer.name + ".png" fullpath = os.path.join(path, name); tmp = dupe.duplicate() #tmp.flatten() pdb.file_png_save(tmp, tmp.layers[0], fullpath, name, 0, 9, 1, 1, 1, 1, 1) dupe.remove_layer(layer) Thanks for the script

nice

I should add that as an option perhaps - to flatten or not.

in windows may be a problem

in windows may be a problem mostly how to chose/wrote the path As use / instead then \ ..or viceversa and blank spaces in the path names, quite commune in Windows( As example C/Documents and Settings/ ) would be supported ?

no problem

Nah - I just tested in XP and it's OK. Both windows and linux have a funkiness though: you have to show the location bar in the file chooser. When you are in the directory to export to, enter a period (.) in the location bar and *then* click open or press enter. But \ or / does not matter, nor do spaces in the path.

fixed the quirk

the script now prompts for a dir, so you don't have to put the "." in there... I used PF_FILE initially, but PF_DIRNAME is correct.

test, test, testing 1, 2, 3...

spam filter working yet? :)
Syndicate content