covert -identify

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
umitdogan

covert -identify

Post by umitdogan »

Hi,
I want to get the width and height of converted image. I got it with -idetify paramter but it is so hard to parse returned string.
How can format the returned string? I tried format but doest work.
Can anyone give me example?
Thank u for help.
Umit
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: covert -identify

Post by Bonzo »

If you are using php you can use getimagesize( )

What do you want to do with the result?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: covert -identify

Post by fmw42 »

convert <image> -format %w info:
convert <image> -format %h info:

or

identify -format %w <image>
identify -format %h <image>

In Unix, you can put these into variables:

width=`identify -format %w <image>`
height=`identify -format %h <image>`

see
http://www.imagemagick.org/script/escape.php

(you can also get image statistics, like the min, max, mean and standard-deviation and other information such as filename, file size, channels, colorspace, etc)


You can also do calculations:

halfwidth=`convert <image> -format "%[fx:w/2]" info:`

etc

see
http://www.imagemagick.org/Usage/transform/#fx_escapes
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: covert -identify

Post by anthony »

You can also output the size directly in a form suitable for use on HTML pages....

Code: Select all

  image=logo.gif
  img_size=`identify -ping -format 'WIDTH="%w" HEIGHT="%h"' "$image"`
  echo "<IMG SRC=\"$image\"  $img_size ALIGN=middle>"
I do this type of thing when generating 'smaller' and 'thumbnail' images of photos, as well as generating a basic HTML index file listing those images.

The -ping option in the above causes identify to attempt to only read enough of the image file to determine simple image information such as size, without trying to read it all in. Most image format files allow you to do this, but not all. This is the advantage of "identify" over "convert"

I have updated the IM Examples Basics section on identify, which should appear in a day or so.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply