Need help with *.bat file for batch resize

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?".
Post Reply
jensaarai
Posts: 2
Joined: 2014-04-01T17:06:45-07:00
Authentication code: 6789

Need help with *.bat file for batch resize

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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
snibgo's IM pages: im.snibgo.com
jensaarai
Posts: 2
Joined: 2014-04-01T17:06:45-07:00
Authentication code: 6789

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

Post by jensaarai »

Thanx
Post Reply