简体   繁体   中英

ImageMagick Command Substitution in Windows Shell

How should i convert the following imagemagick command to use in DOS? As far as i understand i can't convert it directly and have to use a for loop in a batch file, but had no success so far.

convert noisy.jpg -crop `convert noisy.jpg -virtual-pixel edge -blur 0x15 -fuzz 15% -trim -format '%wx%h%O' info:` +repage noisy_trimmed_2.jpg

You'd need the for command in order to capture the output of the command to be passed as a parameter. It can be squeezed into one line by saying:

for /f "usebackq delims=" %%info in (`convert noisy.jpg -virtual-pixel edge -blur 0x15 -fuzz 15% -trim -format '%wx%h%O' info:`) do convert noisy.jpg -crop %%info +repage noisy_trimmed_2.jpg

It is best to rename convert.exe to something like imgConvert.exe so it does not conflict with the Windows convert utility. Otherwise you should run it from the directory where the executable exists or specify the path or use an environment variable to get to it.

The vcomp100.dll is required for convert.exe to execute.

DOS does not like single quotes ('). Use double quotes (") where quotes are needed.

Anyway i got it working like this, and @devnull s answer was helpful but i didn't use "usebackq delims=" . You also need to escape %'s by putting one more % before each.

FOR /F %%A IN ('convert xxx.jpg -virtual-pixel edge -blur 0x15 -fuzz 15%% -trim -format "%%wx%%h%%O" info:') DO convert xxx.jpg -crop %%A +repage yyy.jpg

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM