Page 1 of 1

Need help with *.bat file for batch resize

Posted: 2014-04-01T17:32:00-07:00
by jensaarai
I need to resize multiple images in subfolders. If width<2000 then resize to 1440x2200 and other files to 2880x2200. But i'm getting all files in 1440x2200 and need help :D
@echo off
echo Resizing...
pushd %1
set "%%x==2000"
for /f "delims=" %%n in ('dir /b /s /a-d-h-s') do ("%~dp0identify.exe" -ping -format "%%w" "%%n") & If "%%w" lss "%%x" ("%~dp0mogrify.exe" -resize 1440x2200! "%%n") Else ("%~dp0mogrify.exe" -resize 2880x2200! "%%n")
popd
echo All done!
pause
ImageMagick-6.8.8-10-Q16-x64
Win7 x64

Re: Need help with *.bat file for batch resize

Posted: 2014-04-01T19:04:40-07:00
by snibgo
jensaarai wrote:"%~dp0identify.exe" -ping -format "%%w" "%%n"
This won't set environment variable w, as you will discover if you run it with a filename instead of %%n. Within identify format, "%%w" means "find the width".

That command returns an integer (ie it sends the integer to stdout). If you want to capture the integer into an environment variable (I will use WW to reduce confusion) do something like this:

Code: Select all

F:\web\im>for /F "usebackq" %%L in (`identify -format "WW=%w" x.jpg`) do set %%L

Re: Need help with *.bat file for batch resize

Posted: 2014-04-02T14:57:31-07:00
by jensaarai
Thanx