Gimp-Forum.net
Gimp-Python way to create square-selection Marquee, that user sizes and places? - 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)
+---- Forum: Scripting questions (https://www.gimp-forum.net/Forum-Scripting-questions)
+---- Thread: Gimp-Python way to create square-selection Marquee, that user sizes and places? (/Thread-Gimp-Python-way-to-create-square-selection-Marquee-that-user-sizes-and-places)



Gimp-Python way to create square-selection Marquee, that user sizes and places? - charlweed - 10-17-2022

I want to have gimp help automate the create of 512 square images. Gimp would open each image file in a directory, the user would make a square selection, press a hotkey, and gimp would rescale that selection to 512 by 512 and save it to a different directory.
I (used to, it’s been a few years) know how to open each file in a dir, scale, and save. I don’t know how to GIMP-PYTHON a moveable selection, or to have a hotkey trigger further processing.
I have gimp 2.10.32 (revision 1), but I’m willing to try pre-release gimp 2.99 if that will be much better at what I’m trying to do.
Thanks!


RE: Gimp-Python way to create square-selection Marquee, that user sizes and places? - charlweed - 10-17-2022

(10-17-2022, 06:00 PM)charlweed Wrote: I want to have gimp help automate the create of 512 square images.  ...

Sticking with gimp 2.10, I'm going to try to use "gimp_image_select_rectangle", in one script, and put the saving and scaling in another. I don't know if this is a good way to start.


RE: Gimp-Python way to create square-selection Marquee, that user sizes and places? - Ofnuts - 10-18-2022

Been there, done (nearly) that. The result is in my ofn-file-next script that you can adapt to your needs. It is used like this:

  1. You "manually" open the first image in a series
  2. You do whatever manual processing is required (for me, that was rotate/crop, for you that could be marking a selection or doing the crop)
  3. You hit a key to call the script (you added a shortcut for the script beforehand)
  4. The script finishes the processing (or me nothing to do, for you possibly crop and scale), saves the image, and opens the next in sequence
  5. You are back to #2, with the next image loaded.
So in this workflow, you call a script once per image. This is quite efficient, I handled a couple hundred images in 20 minutes once.

The difference with your requirements:

  1. You can make a selection or a crop. In both cases, you can preset the tool for 1:1 aspect ratio. Doing the crop doesn't take longer (just one keystroke)
  2. I don't scale in the script (in my processing, I did scale, but this was done later in batch using ImageMagick in a shell script). Not hard to add. But if you use the crop in the first step you can use my script directly if you scale in batch.
  3. My script saves the image back to the source file. But you can copy all your files to a squared directory first.
My IM script was like this:

Code:
#! /bin/bash

dir=${1:-.}

for f in "$dir/"*.JPG;  
do
       echo "Processing $f"
       convert "$f" -resize 600x -sharpen 0x1.0 -quality 85 "$dir/$(basename "$f" .JPG).jpg"
done

(it resizes to 600px wide, and does a slight sharpening to mitigate the blur due to the resize). I since found a way to write the script without looping on the files (easier if you are on Windows). You can also use mogrify instead of convert to resize the files directly without making a new copy.


RE: Gimp-Python way to create square-selection Marquee, that user sizes and places? - charlweed - 10-25-2022

Thanks Ofnuts!
I'll take a look.