Gimp-Forum.net
Auto processing the Maze Plugin. - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP)
+--- Thread: Auto processing the Maze Plugin. (/Thread-Auto-processing-the-Maze-Plugin)



Auto processing the Maze Plugin. - ggarrod76@gmail.com - 11-19-2019

Hello everyone,

I've been playing around with the maze generator inside gimp 2.10 creating mazes for FPS game im working on. what i was wondering is there a simple way to have gimp auto generate the mazes as in saying i want 10 mazes with the only thing changing be the random seed. then have them save them selfs as has png to a folder.   

Thanks for any help on this subject.


RE: Auto processing the Maze Plugin. - tmanni - 11-20-2019

You need something like this :

Code:
from gimpfu import *
import os
import os.path


def maze_images(n_images, width, height, export_dir, fg_color, bg_color):
    
    if not os.path.exists(export_dir):
        pdb.gimp_message("Export directory '{}' does not exist".format(export_dir))
        return
    elif not os.path.isdir(export_dir):
        pdb.gimp_message("Export directory '{}' is not a directory".format(export_dir))
        return

    pdb.gimp_context_push()
    pdb.gimp_context_set_foreground(fg_color)
    pdb.gimp_context_set_background(bg_color)
    
    for i in range(n_images):
        seed = i + 1
        name = 'maze-{}'.format(seed)
        filename = name + '.png'
        savepath = os.path.join(export_dir, filename)
        
        image = pdb.gimp_image_new(width, height, RGB)
        layer = pdb.gimp_layer_new(image, width, height, RGB_IMAGE, name, 100.0, LAYER_MODE_NORMAL)
        pdb.gimp_image_insert_layer(image, layer, None, -1)
        pdb.plug_in_maze(image, layer, 10, 10, False, 0, seed, 57, 1)
        pdb.file_png_save(image, layer, savepath, filename, 0, 0, 0, 0, 0, 0, 0)
        pdb.gimp_image_delete(image)

    pdb.gimp_context_pop()
    

register(
    "python_fu_maze_images",
    "Generator maze images",
    "Generator maze images",
    "",
    "",
    "",
    "Maze Images",
    "",
    [
      (PF_INT,   "n_images", "Number of images to generate", 10),
      (PF_INT,   "width",    "image width", 1024),
      (PF_INT,   "height",   "image height", 768),
      (PF_STRING,"export_dir", "Export directory", "/tmp"),
      (PF_COLOR, "fg_color", "Maze foreground color", (255, 255, 255)),
      (PF_COLOR, "bg_color", "Maze background color", (0, 0, 0))
    ],
    [],
    maze_images, menu="<Image>")


main()


Save this python code in a file in the gimp plug-in directory.
Be sure this file has executable permission.
Restart gimp and you will have a new menu entry called Maze Images.
This -quickly done- plug-in will generate n png images called "maze-x.png" where x is the seed used to generate the maze.