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.
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