Mobile app version of vmapp.org
Login or Join
Nickens508

: Image project with multiple selections, export to separate files For a hobby gamedev project I'm looking for a way to automate the following workflow, can be in any photo/image editing tool.

@Nickens508

Posted in: #AdobePhotoshop #CorelPaintShopPro #Export #Gimp #Selections

For a hobby gamedev project I'm looking for a way to automate the following workflow, can be in any photo/image editing tool.


load a high resolution image
make multiple selections
give each selection a name
export each selection to a separate PNG file (with the name)
export coordinates of selections to textfile (name = x,y,h,w)
save image with selections for later use or re-export


So in short, take a highres image, make multiple selections and then export each selection to a separate PNG file, while also exporting a list of the selections coordinates to a text file. See what I mean in the mock up image below:



I'm doing all these steps by hand now and most the images have 70-80 parts. Whenever there is a mistake, image updates, changes in resolution etc. I have to redo large parts or even the whole thing, even though the selections are roughly the same.

Some photo editor programs support plug-ins and scripting, and I can do scripting (lua, python, javascript) no problem. But I don't know of any photo editor that supports saving multiple selections. If you know a good solution to this in any photo editor, like Painshop, PhotoShop, Coral Draw or an OpenSource program like Gimp or Paint Dot Net etc. please let me know.

10.04% popularity Vote Up Vote Down


Login to follow query

More posts by @Nickens508

4 Comments

Sorted by latest first Latest Oldest Best

 

@Murray664

A (fully working) solution as developed by the original poster @BdR and mentioned in this comment. It is the most advanced solution for GIMP so far, and fully works in current GIMP 2.8.


Put the script export_paths_to_png.py into folder ~/.gimp-2.8/plug-ins/ (or the equivalent place on Windows / Mac OS X).
Under Linux, make that script executable:

chmod a+x ~/.gimp-2.8/plug-ins/export_paths_to_png.py

Under Linux, make the generated files use / instead of as directory separators in the script (lines 29 and 68).
Start GIMP.
Create and name GIMP paths for each selection:


Create the selection.
In the "Paths" dialog, click "Selection to path".
Optional: rename your path. The path name will be used as the filename when saving.
Repeat for all your selections.

Click "Filters → Paths → Export paths to PNG" (the menu item added by the script you installed), fill the dialog and click "OK".


Advantages:


Fully works with current GIMP 2.8 (I tested it).
You can save all paths together with your image by saving your image in the GIMP native format .xcf. This saves work when you need to make a few changes and re-export the images later.
When you resize the image, the paths are resized proportionally so they will still "fit".
Paths can overlap without issues, so that a pixel may be exported as part of multiple output images where that is needed.
The names, origin coordinates and sizes of all paths are also saved as a text file orgcoords.json alongside in your output directory, for use with your own scripts. If your paths are simple selections with the GIMP "Rectangle Select Tool", all information about them is contained in the .json file this way.

10% popularity Vote Up Vote Down


 

@Samaraweera207

A (partial / not yet working) solution for GIMP, using a fast semi-automated process of "make a selection, save it as PNG, repeat":


Put the Save Area script into a file ~/.gimp-2.8/scripts/savearea.scm (or the equivalent place on Windows / Mac OS X).
Start GIMP.
Go to "Edit → Keyboard Shortcuts" and assign a keyboard shortcut to the "File → Save area" menu item (the one added by the script you installed). You can use a single key without modifier, for example /.
To use the script:


Make a selection.
Press the shortcut you assigned to access the "File → Save area" feature, and save the selection to a file.
Repeat for all selections you want to save.



Caveats: The script was last updated in 2007, so will probably not work in a current GIMP 2.8 (I did not test it though). But it's a partial solution that could be fixed. Also the installation instructions mention that if the script does not work, one should convert the source images to a different format. PNG with "Image → Mode → RGB" seems a good choice, as the script uses that format itself to save the selections.

10% popularity Vote Up Vote Down


 

@Angie364

A (partial / not yet working) solution for GIMP, using the disjunct pieces ("strokes") of one selection:


Put the GIMP script by Andrew Kvalheim into a file ~/.gimp-2.8/scripts/export-selected-regions.scm (or the equivalent place on Windows / Mac OS X).
Start GIMP.
Create your selection.
Choose "Select → Export Selected Regions" from the menu. (This is the new menu item added by the script.)


Caveats:


As of GIMP 2.8, this script did not work, complaining about "unknown image format". So it will need an update, but then provide a solution. Please report in the comments when you get it to work.
Compared with a solution based on paths (in the other answers here), this solution needs less click-work to define the selections but is only applicable if (1) you do not need self-defined names for your output images and (2) none of your selection pieces overlap (as that would result in one merged "stroke" when defining the selection and consequently in one output image for that "stroke").

10% popularity Vote Up Vote Down


 

@Dunderdale640

But I don't know of any photo editor that supports saving multiple selections.


A solution for Gimp:


In the script, do the equivalent of Select>To path (using the pdb.plug_in_sel2path(image, drawable) function). This will create a path made of several "strokes", each stroke being a closed curve that represents one of your selected items(*).
You can then iterate the strokes in the path, and for each stroke:


create a new path from it
make a selection from that path
create a new layer that contains only that selection
save that layer to file
copy that layer's offset to your data file (note that since the coordinates of the stroke points are readily available, you can also compute the centroid of the object)



For some sample Gimp scripts in Python, including a whole set that deals mostly with paths, see here and here.

(*) Some Gimp paths basics:

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme