J
J
jensaarai2014-04-04 09:47:03
cmd/bat
jensaarai, 2014-04-04 09:47:03

How to solve problem with bat script for Imagemagick to determine image width?

Hello, I'm trying to write a bat-nickname for Imagemagick to resize webp images in a folder with subfolders to two different sizes based on the width of the original image.
The problem is that the width of the image is not defined and ECHO width: %Width% returns an empty value. Tell me what's wrong?

@echo off
pushd %1
SET /A "MaxWidth=2000"
FOR /F "delims=" %%n IN ('dir /b /s /a-d-h-s') do (
    For /F %%# in ("%~dp0identify.exe" -ping -format "%%[fx:w]" "*.webp") DO SET /A "Width=%%#"
    ECHO width: %Width%
    IF  !Width! LSS !MaxWidth! ("%~dp0mogrify.exe" "%%n" -resize 1500x2000! "%%n") ELSE ("%~dp0mogrify.exe" "%%n" -resize 2000x1500! "%%n")
)
popd
echo All done!
PAUSE

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
esx, 2014-04-04
@esx

In the inner For, the parameters are perceived by it as a "list" over which it iterates.
It should be written like this
Single quotes around the command entry.
It's a little unclear why the filename from dir (%n) is not used

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question