Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Accelerate processing of Gimp scripts
#4
(09-25-2022, 02:01 PM)Gimpnik Wrote: Thanks

(09-25-2022, 11:57 AM)Ofnuts Wrote: If Gimp is already started when you call it from a shell, then the arguments are passed to the already loaded instance.
Unfortunately, this is not the case for me on Windows: regardless of whether the tool is already running in the foreground, unfortunately a new separate process instance is currently always executed.

Could be a gimp-console vs gimp thing.

(09-25-2022, 02:01 PM)Gimpnik Wrote:
(09-25-2022, 11:57 AM)Ofnuts Wrote: But of course each "gimp" command in your script will run bow nearly instantaneously because it returns before the work is done, so if each needs the result of the previous one that won't do it.
No, in "batches" is this behavior as you described not usual and Windows Batch Scripts not either unless each gimp command line is executed on the beginning as follows to force a new process instance:
Code:
START "" "%gimp%" …

By default, batch processing, as the name implies, waits unless starting processes in separate instances is enforced (only then does it immediately proceed to the next line).

But you can also force to wait if the default behavior the other way around:
Code:
START "" /WAIT "%gimp%" …

NOTES: Each additional Gimp command line will be executed only after gimp.exe console is closed and in Windows cmd.exe console the batch process is continued (in case by pressing N key for No - to do not cancel batch operation)

Yes, but... when you call the gimp command, it checks if there is an instance running already (unless you use the --new-instance parameter) and if it finds one it passes it the command arguments and the just started instance exits immediately. This is not the same as the started instance continuing in the background (as with START).  Since your batch file waits for the instance it started, it sees that instance terminate and continues. Unless, as above,  a gimp-console vs gimp thing.

(09-25-2022, 02:01 PM)Gimpnik Wrote:
(09-25-2022, 11:57 AM)Ofnuts Wrote: But the first thing to do to improve performance is to string your commands into a single script, and so call gimp only once.
You certainly mean here "into a single command line", because considered as a "file" it is a single script - in my case from this point of view it is the same script, but in another context it is several, depending on how it is viewed.

Of course it is possible but syntax-technically and clearly disastrous, especially because many arguments per command line will follow, which have not been implemented here yet:
Code:
"%gimp%" -i -b "(BatchCropToContent \"*.%FileExtens%\")"
"%gimp%" -i -b "(scale \"*.%FileExtens%\")" "Arg1" "Arg2" "Arg3"
"%gimp%" -i -b "(rotate \"*.%FileExtens%\")" "Arg1" "Arg2" "Arg3"

Simplicity and performance are not always synonyms. But if you make that a true script, then you can possibly compute some of the scale and rotation arguments for some well picked initial arguments, so you likely need fewer parameters than you think.

And btw, while we are at it, rotation and scaling introduce some blur. If you do two operations (one scaling, or rotation), you blur twice.  There are gimp-drawable-transform-2d and gimp-drawable-transform-2d-default functions that do both in one operation so you only blur once.
Reply


Messages In This Thread
RE: Accelerate processing of Gimp scripts - by Ofnuts - 09-25-2022, 02:54 PM

Forum Jump: