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.

  1. load a high resolution image
  2. make multiple selections
  3. give each selection a name
  4. export each selection to a separate PNG file (with the name)
  5. export coordinates of selections to textfile (name = x,y,h,w)
  6. 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:

save multiple selections to seperate images and a coordinates file

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.


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:

Source : Link , Question Author : BdR , Answer Author : xenoid

Leave a Comment