Problems with -format

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
ndee
Posts: 5
Joined: 2012-03-15T05:41:36-07:00
Authentication code: 8675308

Problems with -format

Post by ndee »

Hey everyone,
I am trying to get the image witdth and heigth of an image!
I have googled a lot and found this page: http://www.imagemagick.org/script/identify.php

Identify has an option -format that can give me the height and width of an image. Unfortunately this does not work for me.. Am I doing something wrong?
$ identify -format "%[fx:w/72] by %[fx:h/72] inches" document.png
8.5 x 11 inches

I have a testfile called 000.png and I use this command:
identify -format "%[fx:w/72] by %[fx:h/72] inches" 000.png
My Output is this: w/72] by h/72] inches

My goal is to use this dimensions as variables for later opertations, thats why I need to save them into variables.

Somehow I don't get the dimensions. Does someone know what I am doing wrong? I have installed this imagemagick version: ImageMagick-6.7.6-0-Q16-windows-x64-static.exe


I hope someone can help me!
Thanks in advance,
Andreas
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Problems with -format

Post by Bonzo »

Are you using Windows as it looks like you need to escape the % with another % so it become %%
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problems with -format

Post by fmw42 »

identify -format "%[fx:w/72] by %[fx:h/72] inches" logo:
8.88889 by 6.66667 inches


Works for me on IM 6.7.6.0 Q16 Mac OSX Snow Leopard.

If you are on Windows, then like Bonzo says, escape your % with % as %%
ndee
Posts: 5
Joined: 2012-03-15T05:41:36-07:00
Authentication code: 8675308

Re: Problems with -format

Post by ndee »

Thank you for your answers.

Yep, I am under windows and new to batch programming.

I have now written the command as follows: identify -format "%[fx:w/72]% by %[fx:h/72]% inches" 000.png
My output is still the same: w/72][fx:h/72] inches
Other operations work fine, as for example just: identify 000.png

Hmm... I am a bit confused!
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Problems with -format

Post by Bonzo »

Code: Select all

%%[fx:w/72] by %%[fx:h/72]
Some batch file examples on my site may be helpful: http://www.rubblewebs.co.uk/imagemagick/batch.php

Some Imagemagick examples here: http://www.imagemagick.org/Usage/windows/
ndee
Posts: 5
Joined: 2012-03-15T05:41:36-07:00
Authentication code: 8675308

Re: Problems with -format

Post by ndee »

Awesome!!
Thanks alot Bonzo! And all others.

This works! I will take a look at your site for sure!!

Once Again! Thanks alot!
ndee
Posts: 5
Joined: 2012-03-15T05:41:36-07:00
Authentication code: 8675308

Re: Problems with -format

Post by ndee »

Ok.. I hope this is my last question for this thread!

How can I save the width and height values into a variable?

Here is what I tried:

echo off
identify -format %%w 000.png
set width=%%w
echo %width%

This came out:
1778
%w
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problems with -format

Post by fmw42 »

Post Reply