0

Background

During my online D&D session I grab period screen captures of the active window which is showing a 2D map or the area my token can see. As a result, all the images are the exact same size, and part of the image I do not want to keep are always in the exact same spot and the exact same size. My ultimate goal is to trim down the images to just the just the map portion and then stitch them all together to create and over all map.

In terms of research, I tired searching this site for GIMP BIMP BATCH CUT. I found this question, but it was mainly photoshop macro recording and a slightly different issue.

Plan

Using Gimp with BIMP plug-in for batch processing

  1. Perform the same crop on all pictures to remove most of the excess boarder crud that is not wanted
  2. Cut the residual crud using selection identical selections boxes and locations. Repeat this for each piece to be cut out.
  3. Convert the black to transparent or white so that only the map remains. Hope this helps with stitching process

Using Hugin to stitch

  1. Dump all the photos into Hugin for auto alignment and stitching. I do not need perfect or even high quality results as I plan to then use the stitched image for rough tracing.

Tracing from a single image is much faster then pulling in, scaling and aligning the individual files.

What I have tried

I used BIMP to perform two separate runs to achieve the basic crop. I used two opposite reference corners and supplied appropriate dimensions for height and width. This has left me with an images that look something like this:

enter image description here

Question

How can I batch process the same cut out via batch processing?

Before:

enter image description here

After:

enter image description here

Ultimate:

enter image description here

Alternatively is there an alternate way to achieve the batch processing goal?

Alternate Image

Same screen but on a different part of the map to show how it moves around.

enter image description here

7
  • Why dont you capture only the part you need?
    – joojaa
    Apr 21, 2022 at 6:40
  • @joojaa - The part I need keeps moving around and changing shape. The parts I don't need are constant.
    – Forward Ed
    Apr 21, 2022 at 6:43
  • Err thats the same thing only upside down. You do know that you can instruct the os to only grab a specific area. Anyways sounds like something id use imagemagik for. As irs easier being thet the user interface is designed to be used from script and command line.
    – joojaa
    Apr 21, 2022 at 6:45
  • @joojaa I do not know how to make BIMP cut out any area
    – Forward Ed
    Apr 21, 2022 at 6:47
  • Thats why i suggested imagemagik because its better documented and faster.
    – joojaa
    Apr 21, 2022 at 6:50

1 Answer 1

0

To crop the images, remove a fixed portion and save it all at once:

  1. Copy this GIMP python-fu script:
#!/usr/bin/env python

from gimpfu import *

def clear_selection_on_all_layers(image, drawable):
    # Get the list of layers in the image
    layers = image.layers
    
    # Loop through each layer and clear the selection
    for layer in layers:
        # Set the layer as the active layer
        pdb.gimp_image_set_active_layer(image, layer)
        
        # Clear the layer using the selection
        pdb.gimp_edit_clear(layer)

    # Refresh the display
    gimp.displays_flush()

# Register the script in GIMP
register(
    "python_fu_clear_selection_on_all_layers",
    "Clear selection on all layers",
    "Clear selection on all layers in the current image",
    "Fabrice TIERCELIN",
    "Fabrice TIERCELIN",
    "2023",
    "<Image>/Filters/Clear Selection on All Layers",
    "*",
    [],
    [],
    clear_selection_on_all_layers
)

main()
  1. Paste it into a text file
  2. Save it with a .py extension
  3. Put this file on your C:\Users\YourName\AppData\Roaming\GIMP\2.10\plug-ins folder (more information below if it doesn't work)
  4. Do the same with this second GIMP python-fu script:
#!/usr/bin/env python

from gimpfu import *

def export_layers(image, drawable, extension, path):
    # Get the layers of the image
    layers = image.layers

    # Export each layer to a separate file
    for i, layer in enumerate(layers):
        filename = path + '/' + layer.name + '.' + extension
        pdb.gimp_file_save(image, layer, filename, filename)

    gimp.message("All layers have been exported as separate files.")

register(
    "python-fu-export-layers",
    "Export Each Layer as a Separate file",
    "Exports each layer of the image as a separate file",
    "Fabrice TIERCELIN",
    "Fabrice TIERCELIN",
    "2023",
    "<Image>/File/Export Layers...",
    "*",
    [
        (PF_STRING, "extension", "Extension", "png"),
        (PF_DIRNAME, "path", "Directory", "C:\Users\YourName\Desktop")
    ],
    [],
    export_layers)

main()
  1. Restart GIMP
  2. Open the first image in GIMP
  3. Open the remaining images in GIMP using drag-n-drop: all the images become layers in the same image
  4. Select the new border
  5. Click on Image -> Crop from the selection: all the images are cropped
  6. Select the part to clear
  7. Go on FilterClear Selection on All Layers
  8. Launch the script
  9. Go on FileExport Layers...
  10. Launch the script

Your images are saved.

For systems other than Windows, look at the settings in GIMP:

  1. Click on Edit
  2. Click on Preferences
  3. Go on left pane, at bottom
  4. Click on Folders
  5. Click on Plug-ins
  6. Click on Add a new folder

Successfully tested on GIMP 2.10.36 on Windows 10.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.