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
covert -identify
Re: covert -identify
If you are using php you can use getimagesize( )
What do you want to do with the result?
What do you want to do with the result?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: covert -identify
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
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
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: covert -identify
You can also output the size directly in a form suitable for use on HTML pages....
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.
Code: Select all
image=logo.gif
img_size=`identify -ping -format 'WIDTH="%w" HEIGHT="%h"' "$image"`
echo "<IMG SRC=\"$image\" $img_size ALIGN=middle>"
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/
https://imagemagick.org/Usage/