下面的代码将在根目录中提取图片的宽度和高度。
@ECHO OFF &SETLOCAL
(for /r %%a in (*.jpg) do (
for /f "tokens=1*delims=:" %%b in ('"MEDIAINFO --INFORM=Image;%%Width%%:%%Height%% "%%~a""') do (
echo(%%b %%~c)
))
pause
%%b 和 %%~c 将存储宽度和高度,正如您在代码中看到的那样,没有 %%~c 变量,但它仍然有效。我想执行以下命令:
after getting width and height with above code
if width>height
w=width-100
resize picture /width=w
else
h=height-100
resize picture /height=h
我将使用 cmd 实用程序调整大小,但问题是将 %%b 和 %%~c 分配给两个变量并将它们相互比较。
最佳答案
试试这个:
@ECHO OFF
SETLOCAL enabledelayedexpansion
set "MI=U:\scripts\utilities\Mediainfo\Mediainfo.exe"
for /r %%a in (*.jpg) do (
for /f "tokens=1,2 delims=:" %%b in ('"%MI% --INFORM=Image;%%Width%%:%%Height%% "%%~a""') do (
echo(%%b %%c
if %%b GTR %%c (
set /a w=%%b-100
Echo resize picture /width=!w!
) ELSE (
set /a h=%%c-100
Echo resize picture /height=!h!
)
)
)
pause
关于windows - 执行一些命令取决于图片的宽度和高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21760677/