for %%i in (%*) do (
set /p Var1="Enter Pixel Size: "
convert "%1" -thumbnail %Var1%x -unsharp 1.5x1.2+1.0+0.10 "%~p1%~n1"
)
With this file I am trying to convert multiple images through a batch file, at different sized.
PROBLEM: The Var1 asks the user to enter a size, then it gets processed for the image placed. But when I prompt the user for an image size while trying to convert multiple files, only the first file takes effect and its size. It'll ask me for the second size, but for the first file, then it prompts me if I want to replace that file or not.
WHAT I WANTED: I was hoping that the file would run through each image, ask for its size, and convert it one at a time, being able to replace Var1 with the most updated pixel for the most updated image that needs conversion.
A few issues:
setlocal enabledelayedexpansion
for %%i in (%*) do (
set /p Var1="Enter Pixel Size: "
convert "%%i" -thumbnail !Var1!x -unsharp 1.5x1.2+1.0+0.10 "%%~pi%%~ni"
)
You need to turn on EnableDelayedExpansion to support the "!" syntax for variables to be expanded when the line is parsed, not the block they're in. Instead of passing %1
to the convert command, pass %%i
to it to pass the filename from the for
loop. Then, you can pass !Var1!
instead of %Var1%
so the latest changes to Var1 are passed to the convert program.