Discussion:
extract info from identify output
AngeloChen
2011-11-04 07:38:34 UTC
Permalink
Hi,

I'm using identify to get width, height and size of a jpeg, I assume that
the size is always in the offset 6, but seems not the case, following are
two jpeg files, the sample2.jpg has an additional field '256c', what is a
reliable way to extract size of file from the output of identify?

sample1.jpg JPEG 320x400 320x400+0+0 8-bit DirectClass 60.2KB 0.000u
0:00.000
sample2.jpg JPEG 375x600 375x600+0+0 8-bit PseudoClass 256c 79KB 0.000u
0:00.000

Angelo
--
View this message in context: http://old.nabble.com/extract-info-from-identify-output-tp32778603p32778603.html
Sent from the Magick-users mailing list archive at Nabble.com.
Fred Weinhaus
2011-11-04 17:27:35 UTC
Permalink
Much easier to use string formats:

width=`convert image -ping -format "%w" info:`
height=`convert image -ping -format "%h" info:`
filesize=`convert image -ping -format "%b" info:`

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

The above is unix command to put the results into variables. For
windows, see http://www.imagemagick.org/Usage/windows/

Fred
Post by AngeloChen
Hi,
I'm using identify to get width, height and size of a jpeg, I assume that
the size is always in the offset 6, but seems not the case, following are
two jpeg files, the sample2.jpg has an additional field '256c', what is a
reliable way to extract size of file from the output of identify?
sample1.jpg JPEG 320x400 320x400+0+0 8-bit DirectClass 60.2KB 0.000u
0:00.000
sample2.jpg JPEG 375x600 375x600+0+0 8-bit PseudoClass 256c 79KB 0.000u
0:00.000
Angelo
--
http://old.nabble.com/extract-info-from-identify-output-tp32778603p32778603.html
Sent from the Magick-users mailing list archive at Nabble.com.
Anthony Thyssen
2011-11-05 05:26:27 UTC
Permalink
On Fri, 4 Nov 2011 10:27:35 -0700
Fred Weinhaus <***@alink.net> wrote:
| Much easier to use string formats:
|
| width=`convert image -ping -format "%w" info:`
| height=`convert image -ping -format "%h" info:`
| filesize=`convert image -ping -format "%b" info:`
|
| See
| http://www.imagemagick.org/script/escape.php
|
| The above is unix command to put the results into variables. For
| windows, see http://www.imagemagick.org/Usage/windows/
|

Another way that can be used for BASH scripting is a multi-field
read. For example...

read width height filesize \
<<< $( convert -ping rose: -format "%w %h %b" info: )

echo $width $height $filesize
70 46 9673B

This is very advanced but works very well!

PS: it is a good idea that -ping is put before the image!


Anthony Thyssen ( System Programmer ) <***@griffith.edu.au>
--------------------------------------------------------------------------
The warrior didn't speak, for his mouth was full. -- "Kung Fu Panda"
--------------------------------------------------------------------------
Anthony's Castle http://www.ict.griffith.edu.au/anthony/

Continue reading on narkive:
Loading...