6

On my windows machine, I want to use GIMP to modify all PNG files (filename.png) in the current directory and to save the output file to the sub-directory out/filename.png. The processing that is needed is:

  • adding rounded corners
  • adding drop shadow
  • resizing the image

For that, I tried to use the following script and placed it under C:\Program files\GIMP\share\gimp\2.0\scripts:

(define (script-fu-shadowcorners infile outfile width height)
  (let* ((image (car (file-png-load 1 infile infile)))
         (drawable (car (gimp-image-active-drawable image)))
        )
    (script-fu-round-corners image drawable 10 FALSE 8 8 30 FALSE FALSE)
    (script-fu-drop-shadow image drawable 8 8 12 '(0 0 0) 45 TRUE)
    (gimp-image-scale image width height)
    (gimp-file-save RUN-NONINTERACTIVE image drawable outfile outfile)
  )
)

(script-fu-register "script-fu-shadowcorners" "" "" "" "" "" "RGB*" SF-FILENAME "Infile" "infile.png" SF-FILENAME "Outfile" "outfile.png")

Afterwards, I tried to call this script with the following batch file:

for %%x in (*.png) do "C:\Program files\GIMP\bin\gimp-2.8" -i -b "(script-fu-shadowcorners \"%%x\" \"newfolder\\%%x\")"

It did not work. It does always say it could not find the files, it's very slow, and there is no output.

Now that the CMD command works, at least, the problem is not completely solved. In CMD, there appears a line after my batch command that replaces the %%x wildcard by the first file name - but only the first. In the output directory, I can not find files other than the first one, either. Nevertheless, Gimp's output is batch command executed successfully.

What am I doing wrong? Can you help me? Thank you very much!

caw
  • 198
  • 1
  • 3
  • 15
  • 1
    Does the command work with a single PNG specified at the command line? Ensure paths with spaces (such as to the gimp-2.8 dir) are quoted. Also, try adding an `echo` before "C:\Program files... in the *for* loop and see what's printed out. Are the paths to the PNGs ok? – Karan Jan 16 '13 at 02:59
  • Thank you! It turned out that the correct command would have been this one-liner: `for %%x in (*.png) do "C:\Program files\GIMP\bin\gimp-2.8" -i -b "(script-fu-functionname \"%%x\" \"newfolder\\%%x\")"` – caw Jan 16 '13 at 18:08
  • Unfortunately, this does only process 1 of the 24 `.png` files in my directory. Can anybody see why? – caw Jan 16 '13 at 18:09
  • Any errors causing the script to abort? I'm actually getting confused by that script-fu bit - do you really need to escape the quotes with backslashes for it? – Karan Jan 16 '13 at 18:10
  • Yes, that's correct and necessary, as the whole script-fu parameter is wrapped by quotes as well, so you have to escape the inner quotes. This is what made it working. Since script-fu starts and one PNG is modified, we can be sure that this syntax is correct. The question is what lets script-fu cancel its job?! – caw Jan 16 '13 at 18:30
  • 2
    If you run it at the command-line (replace all %% with single %), after closing Gimp when it's done with the 1st PNG, does it print the command for the 2nd PNG? – Karan Jan 16 '13 at 18:33
  • Strangely, it processes *all* files if I use the same command (except for the double `%`) in the command line. Why doesn't it work when it's in the batch file? – caw Jan 16 '13 at 18:44
  • When I add `-b "(gimp-quit 0)"` to the batch file content, it processes all files as well. However, it always requires me to "press any key" before proceeding to the next image. – caw Jan 16 '13 at 18:47
  • Probably because at the cmd line it runs one command then returns, whereas in the batch file it runs and waits for you to quit the launched program i.e. Gimp before it can continue with the loop. – Karan Jan 16 '13 at 18:52
  • No, in CMD it did even run without the `gimp-quit` command at the end. Is there any way to make that work in the batch file as well or to skip the "press any key" prompts when using `gimp-quit`? – caw Jan 16 '13 at 18:55
  • Do you have a `pause` anywhere in the batch file? If so, remove it and see. – Karan Jan 16 '13 at 18:59
  • No, removed that already before. – caw Jan 16 '13 at 19:02
  • Can you edit the question and copy-paste the contents of the batch file? – Karan Jan 16 '13 at 23:02
  • Did that already, you can find the updated contents in the question above. – caw Jan 16 '13 at 23:46
  • Well the official [tutorials](http://www.gimp.org/tutorials/Basic_Batch/) all have gimp-quit included, but I would have thought -i for no interface would imply the ability to run silently without requiring user input. No idea why Gimp is pausing. – Karan Jan 16 '13 at 23:50
  • Thank you, Karan! Finally found the problem, please see my answer below. – caw Jan 17 '13 at 01:37
  • Does this answer your question? [Using Gimp to batch convert images to another format in Windows](https://superuser.com/questions/77429/using-gimp-to-batch-convert-images-to-another-format-in-windows) – wmassingham May 07 '21 at 18:02

1 Answers1

8

The solution had two parts:

Part 1: The syntax of the batch command was wrong, especially the quotes need to be set correctly:

for %%x in (*.png) do "C:\Program files\GIMP\bin\gimp-2.8" -i -b "(script-fu-functionname \"%%x\"

Parts 2: Gimp always waiting for me to "press any key" was due to the wrong binary used: Instead of gimp-2.8, gimp-console-2.8 must be used.

Thanks, Karan, for hinting at the solutions.

caw
  • 198
  • 1
  • 3
  • 15
  • Took me a while to figure out the double-quotes behavior. Thanks, this helped a lot! Here's a gist which even finds the path via registry: https://gist.github.com/tresf/1bd76fc8cd4a4def215c68cab990dfb1 – tresf Apr 23 '20 at 17:52