Page 1 of 1
Get image "Type" with identify ?
Posted: 2008-11-06T07:22:06-07:00
by Bingo
Hi all !
When I use "identify -verbose" on an image, I have a "Type" field that tells whether the image is Palette, PaletteMatte, TrueColor, TrueColorMate, etc...
How do I get only this information with "identify -format" ?
Thanks a lot !
Edit : Just to make the point clear... I have a huge bunch of files, some are "Palette", some are "TrueColor", some are "TrueColorMatte" and some "PaletteMatte". I need to identify the "PaletteMatte" ones (probably from vbscript, with the activex)
Re: Get image "Type" with identify ?
Posted: 2008-11-06T07:45:58-07:00
by magick
Try -format %r.
Re: Get image "Type" with identify ?
Posted: 2008-11-06T07:51:57-07:00
by Bingo
Thanks for your answer.
%r gives me "DirectClassRGB".
That looks like a combination of the "Class" and "ColorSpace" fields from the -verbose output, but that's not what I am looking for.
Re: Get image "Type" with identify ?
Posted: 2008-11-06T08:34:42-07:00
by magick
The -format option only returns readily available metadata that does not require a pass over the image pixels. What you want, the image type, requires a pass over the image pixels which can be expensive and is only available with the -verbose option. You can write a shell script to extract the image type from the verbose output or use one of the MagickCore API wrappers such as PerlMagick. With just a few lines in the PerlMagick script it can return the image type.
Re: Get image "Type" with identify ?
Posted: 2008-11-06T10:41:10-07:00
by Bonzo
Not the best way to do this but using php this will work:
Code: Select all
<?php
$sourcefile = "imagemagick/original_images/sunflower.jpg";
$cmd = "identify -verbose ".$sourcefile;
exec( "$cmd 2>&1", &$o, $r );
$return = ( "\n<pre>\n".join( "\n", $o )."\n</pre>\n" );
$start = strpos( $return, "Type:" );
$result = substr( $return, $start );
$length = strpos( $result, "\n" );
$result = substr( $result, 5, $length-5 );
echo "Type = $result";
?>
Re: Get image "Type" with identify ?
Posted: 2008-11-07T00:39:48-07:00
by Bingo
Oh OK you just meant extracting the information from the "verbose" output.
I can do that.
Thanks for your help guys !