Expand an Open Raster Image (.ora) and Maintain the Structure
One way to quickly export all the image layers in your graphics file to png is to export it as an .ora file (Open Raster Image).
They're basically just a zip file but the images get saved with OS friendly names and a mapping file (stacks.xml) is created to map the original layer names to the file system safe ones it generates.
Cool because now you just need to stick the .zip extension on your .ora file and you can export those nice png images for use elsewhere.
It's a very portable format, especially on linux when GIMP updates their .xcf format and you're waiting for the other lovely free software writers to catch up! (for a while you can't import the latest .xcf format).
Problem is you have to identify the images and rename them all to the original names.
explode_ora.py is a simple Python script that unzips the file, creates a directory for your main file (in your current directory) and then creates sub-directories for your layer groups and exports and renames your image files to their original layer names in the stacks.xml mapping file.
Obviously, you need Python installed - though it doesn't use any non-standard libraries.
It's quick and dirty so it doesn't sanitise the layer names or layer group names which means it will moan about any duplicates in the same layer group and doesn't like weird characters for names. Long names will also be a problem on Windows where the limit is 255 characters but if you name everything sensibly in your graphics / photo editor then it will handle most .ora files.
Here's the script file:
explode_ora.zip
Usage is:
explode_ora.py < file name >
Add it to your .bash_aliases (Ubuntu) or .bashrc to use it anywhere. Copy the script to your home directory then on Ubuntu:
nano ~/.bash_aliases
Add:
alias explode_ora="python3 ~/explode_ora.py"
Example usage (.ora file is in current directory):
explode_ora myfile.ora
Voila! A nice directory structured just like your original image file...