Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Automation questions.
#3
(10-10-2019, 07:07 AM)Ofnuts Wrote: For a general way to call Python scripts in batch, see here.

There is no API to export paths as SVG, but the path data is easy to obtain. See here for my collection of path-related scripts, in particular path-csv that imports/exports the path contents from/to a CSV file.

Also some background on paths with a Gimp perspective here.

Thank you for the prompt and informative answer!

I have created the following plugin and managed to export the information I need to use within python:

Code:
#!/usr/bin/env python

from gimpfu import *


def green_path(wall_color, image_file):
   image = pdb.gimp_file_load(image_file, image_file)
   drawable = pdb.gimp_image_get_active_drawable(image)
   pdb.gimp_image_select_color(image, 0, drawable, wall_color)
   pdb.gimp_selection_shrink(image, 4)
   pdb.gimp_selection_sharpen(image)
   pdb.plug_in_sel2path(image, drawable)
   active_vectors = pdb.gimp_image_get_active_vectors(image)
   vector_string = pdb.gimp_vectors_export_to_string(image, active_vectors)

   return pdb.gimp_message(vector_string)


register(
   "python-fu-green-path",
   "Green walls to path",
   "Converts green walls into a path",
   "Nicolas San Martin", "Nicolas San Martin", "2019",
   "Green walls to path",
   "",
   [
       (PF_STRING, "wall_color", "Color of the walls to be converted", None),
       (PF_FILE, "image_file", "Path to the Mask Dungeon (70px)", None)
   ],
   [],
   green_path, menu="<Image>/Tools")

main()

The only problem I seem to be having now is that it creates a lot of nodes. It's not a problem with the script but how GIMP creates the path based on the selection. Using an image such as this one and selecting the green "walls" in the dungeon, it generates two parallel paths based on the edges of the selection. I have attached two example output .svg files with 0px and 4px shrinking.

Is there any way to generate a single path/line in the middle of the selection? (I don't need it to be perfect, the path should be formed as series of narrow straight lines going through the middle of the green wall to use as few nodes as possible).

Thank you!


Attached Files
.svg   full.svg (Size: 76.27 KB / Downloads: 213)
.svg   shrunk_4px.svg (Size: 84.07 KB / Downloads: 186)
Reply


Messages In This Thread
Automation questions. - by PSNick - 10-10-2019, 01:00 AM
RE: Automation questions. - by Ofnuts - 10-10-2019, 07:07 AM
RE: Automation questions. - by PSNick - 10-11-2019, 04:45 AM
RE: Automation questions. - by Ofnuts - 10-11-2019, 06:24 AM
RE: Automation questions. - by rich2005 - 10-11-2019, 08:41 AM
RE: Automation questions. - by PSNick - 10-13-2019, 01:48 AM
RE: Automation questions. - by Ofnuts - 10-13-2019, 09:18 AM

Forum Jump: