"identify" command in nested FOR loop (windows batch)

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Locked
ElPeta
Posts: 8
Joined: 2019-08-30T16:48:48-07:00
Authentication code: 1152

"identify" command in nested FOR loop (windows batch)

Post by ElPeta »

Hi all,

Trying to do a Windows batch script that recursively adds a watermark, and changes its size proportionally according to the size of each image within a folder. Pretty much, this is what script should do:

1. Count the number of files inside a folder to afterwards use variable in for loop.
1a. Check image size of each image inside said folder
1b. Calculate proportional size of watermark to be added
1c. Add watermark to each
2. Repeat until every image is processed.
3. End.

I am stuck in the nested FOR loop that iterates between each, file, checks its size and calculates the proportional size of the watermark to be added. I added some echoes just to check if it is correctly iterating, and one of the nested FORs is, while the other one isn't.
Here's my code.

Code: Select all

rem Count files inside folder
for /f %%A in ('dir ^| find "File(s)"') do set cnt=%%A
echo Number of files: %cnt%
echo.

rem Below cycle should read image size and store it in variable 
for /L %%i in (1,1,%cnt%) do (
	echo iCount = %%i
	identify -ping -format "width=%%w\nheight=%%h" ^
	IMG%%i.JPG`) do set %%J

rem Calculate proportional width
set /A defaultWidth=5184
set /A PropLogoWidthStep1=%width%*1003
set /A PropLogoWidth=%PropLogoWidthStep1%/%defaultWidth%

rem Print variables in screen
echo.
echo ------------IMG %i%------------
echo Width : %width%
echo Height: %height% 
echo Proportional Width: %PropLogoWidth%
echo %%i
)
As you may have already noticed, I'm both and ImageMagick and a Batch script newbie, so I would really appreciate your help.

Thanks so much!

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: "identify" command in nested for loop (windows batch)

Post by snibgo »

You have a loop with "for ... do ... do ...". It should have only one "do".
snibgo's IM pages: im.snibgo.com

ElPeta
Posts: 8
Joined: 2019-08-30T16:48:48-07:00
Authentication code: 1152

Re: "identify" command in nested FOR loop (windows batch)

Post by ElPeta »

snibgo wrote:
2020-03-01T12:34:05-07:00
You have a loop with "for ... do ... do ...". It should have only one "do".
Thanks, snibgo. But I'm trying to do two nested FOR cycles. Obvioulsy I am doing it wrong, but I can't find why!

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: "identify" command in nested FOR loop (windows batch)

Post by snibgo »

You can nest one "for ... do ..." loop inside another "for ... do ..." loop. But you haven't. You have "for ... do ... do...". Can you see the difference?
snibgo's IM pages: im.snibgo.com

Locked