Gimp-Forum.net
Way to script manual rectangle definition? - 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: Way to script manual rectangle definition? (/Thread-Way-to-script-manual-rectangle-definition)



Way to script manual rectangle definition? - charlweed - 06-05-2018

I want my script to have the user use the mouse to define a rectangle, then the script continues. It's less good to make my user create a rectangular selection, then start the script.
I am trying to avoid the situation where the user must
    start script A
    use the rectangle tool/shortcut to get a selection
    start script B to convert selection into rectangle and continue.
Is there a way to do this?
 
Basically, I have a large number of full length portraits with many different poses. Each portrait needs to be hand-cropped into a Square bust portrait. I've figured out most everything except how to tell the GIMP: "Here, the user defines a rectangle with the mouse."

I'm using GIMP 2.10.2, and python scripting, on Linux and Windows.

Thanks!


RE: Way to script manual rectangle definition? - Ofnuts - 06-06-2018

You cannot have a GUI interaction  in a script. Typically you would ask the user to define the rectangle before calling your script.

If you have to process many pictures in sequence, you can do this:

  1. load the first image and do the initial processing
  2. let the user define the square
  3. run a second script that:
    • does the second part of the process
    • saves/exports the image
    • loads the next image and does the initial processing
  4. go to step 2
Then the script #1 is run once, and script #2 is run once for each image: except for the first, you have only one interaction per image. For an example see my ofn-file-next script.


RE: Way to script manual rectangle definition? - rich2005 - 06-06-2018

Just a thought, the gmic plugin could be a workaround, although if more convenient than making a selection then invoking a script is debatable.

The regular frame filter, with the frame settings zero'd will crop an image with a preview.

screenshot: https://i.imgur.com/rDmwk4b.jpg

and of course those settings can be saved for the next image. Percentage sliders? Depends how accurate you want to be.