Thursday, February 22, 2018

Batch conversion for images from command line on Windows



I have a script based on GIMP batch tutorial:



  (define (batch-colorize pattern
hue
saturation
lightness)

(let* ((filelist (cadr (file-glob pattern 1))))
(while (not (null? filelist))
(let* ((filename (car filelist))
(image (car (gimp-file-load RUN-NONINTERACTIVE
filename filename)))
(drawable (car (gimp-image-get-active-layer image))))
(gimp-colorize drawable
hue saturation lightness)
(gimp-file-save RUN-NONINTERACTIVE
image drawable filename filename)

(gimp-image-delete image))
(set! filelist (cdr filelist)))))


So now in the folder with my images with cmd I run:




SET gimpEXE="C:\Program Files\GIMP 2\bin\gimp-2.8.exe"



%gimpEXE% -i -b "(batch-colorize *.png 90 73 15)" -b "(gimp-quit 0)";





But then GIMP says:




batch command experienced an execution error:



Error: ( : 1) eval: unbound variable: *.png





So then I tried:




%gimpEXE% -i -b "(batch-colorize ""*.png"" 90 73 15)" -b "(gimp-quit 0)";




But then GIMP says:




GIMP-Error: Failed to open file C:\myfolder\with\png\90: No such file or directory




GIMP-Error: Failed to open file C:\myfolder\with\png\73: No such file or directory



GIMP-Error: Failed to open file C:\myfolder\with\png\15: No such file or directory



GIMP-Error: Failed to open file C:\myfolder\with\png\0: No such file or directory




So then I tried what was in an original example (witch I assume is for Linux):





%gimpEXE% -i -b '(batch-colorize "*.png" 90 73 15)' -b '(gimp-quit 0)'




But then GIMP says all above and:




GIMP-Error: Failed to open file "C:\myfolder\with\png*.png": Unable to open "C:\myfolder\with\png*.png" for reading: Invalid argument



Answer




You're assuming that the OS is going to expand the *.png for you, but since it's buried inside the quoted string for the command line argument, the expansion won't happen. This should fix the issue:



SET gimpEXE="C:\Program Files\GIMP 2\bin\gimp-2.8.exe"
for %%i in (*.png) do %gimpEXE% -i -b "(batch-colorize %%i 90 73 15)" -b "(gimp-quit 0)"


Note that the %%i is only necessary if this is contained in a batch file. If you're running the command directly at the prompt, %i is required instead.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...