Page 1 of 1

How to get image size?

Posted: 2011-04-26T01:55:18-07:00
by wc2005
Hello, everybody!
I am new to ImageMagick. I am using ImageMagick-6.6.9-Q16-windows on Windows XP. I want to get the size of the image which is previously resized for later use, how can I do that? Please help, thanks.

Re: How to get image size?

Posted: 2011-04-26T09:35:48-07:00
by fmw42
see string formats at http://www.imagemagick.org/script/escape.php

convert image -format "%w x %h" info:

gives the image width and height.

You can add -ping to make it faster by not reading the whole image

convert image -ping -format "%w x %h" info:

Re: How to get image size?

Posted: 2011-04-26T21:05:36-07:00
by wc2005
Thanks for your help.
Your code works but please look at my .bat file below (the code creates reflection effect for an image):

Code: Select all

set s=960x1280
convert  "c:\h.jpg" -alpha on -background transparent -gravity South -extent %s% ( +clone -flip ( -size %s% gradient:"rgba(0,0,0,0.6)-none" -size 10x0 xc:none  -append ) -compose Dst_In -composite ( -size %s% gradient:black-white ) -compose Blur -set option:compose:args 2x2 -composite ) -append  "c:\a.png"
When I want to create reflection effect for an image, I have to see its properties to get its width and height to assign to variable s as the code above. Now, I want ImageMagick to get width and height of the image automatically but the code below does not work:

Code: Select all

convert  "c:\h.jpg" -alpha on -background transparent -gravity South -extent %%wx%%h ( +clone -flip ( -size %%wx%%h gradient:"rgba(0,0,0,0.6)-none" -size 10x0 xc:none  -append ) -compose Dst_In -composite ( -size %%wx%%h gradient:black-white ) -compose Blur -set option:compose:args 2x2 -composite ) -append  "c:\a.png"
Please help me, thanks.

Re: How to get image size?

Posted: 2011-04-26T21:18:23-07:00
by fmw42
Sorry I am not a Windows user nor do I know Bat scripting. When you say it does not work, that does not help as you don't say how it does not work. So I would suggest you place -write tmp1.png and -write tmp2.png etc in various places to track your different complex steps. Then you can find out where things are going wrong.

Note also you cannot get width and height calculated in-line with %w and %h in specifying -size, such as -size %%wx%%h or -extent %%wx%%h, assuming I am interpreting your commands correctly. If you have variables for w and h already, then you can specify them in -size or -extent, but you cannot compute them while doing -size or -extent.

Also perhaps you should first split your command into several commands with specific output files and get that to work, before you try to put them all together into one complex command line. That way, if you need to, you can compute image sizes as variables between steps for use in the next step.

Re: How to get image size?

Posted: 2011-04-27T05:34:05-07:00
by wc2005
Yeah, I had some problems with .bat file, I searched around and it now works. Thanks a lot for your help! :D