Page 1 of 1

Trouble registering a variable

Posted: 04 May 2014 19:59
by jonathanjohnson100
I want to get the width and height from imagemagick

I'm having trouble doing this

I have this:

Code: Select all

set /a w=`identify -format "%w" bmw.png`

I got this in an example I got googling
I've tried without the backtick characters as well

I get an operator missing error

I just wanted to check if I was doing something wrong in DOS?
If it's imagemagick, then at least I know I need to look that up

Thanks in advance


JJ

Re: Trouble registering a variable

Posted: 05 May 2014 06:11
by Squashman
Batch is not like Unix based shells. You need to use a FOR /F just like you did in your other post with the DIR command.

Re: Trouble registering a variable

Posted: 05 May 2014 06:17
by Compo
Drop the /a switch too; you are not doing arithmetic, (only setting a variable to a number); see Set /? for more info.

Something like this perhaps!

Code: Select all

@Echo off & SetLocal
If "%~1" Equ "" GoTo :EOF
If Not Exist "%~1" GoTo :EOF
(Set _inputFile=%~1)
(Set _IMDir=C:\Program Files\ImageMagicK)
PushD %_IMDir%||GoTo :EOF
For /f "UseBackQ" %%A In (`identify -format "_w=%%w\n_h=%%h" "%_inputFile%"`) Do (Set %%A)
Echo(Width is %_w%, Height is %_h%
EndLocal & Pause
Change line 5 to match your ImageMagicK installation directory then drag and drop an image onto the script to test.