Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gimp-Python way to create square-selection Marquee, that user sizes and places?
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.
(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.
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:

#! /bin/bash


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

(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.
Thanks Ofnuts!
I'll take a look.

Forum Jump: