Get image "Type" with identify ?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Bingo
Posts: 24
Joined: 2007-03-26T03:43:14-07:00

Get image "Type" with identify ?

Post 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)
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Get image "Type" with identify ?

Post by magick »

Try -format %r.
Bingo
Posts: 24
Joined: 2007-03-26T03:43:14-07:00

Re: Get image "Type" with identify ?

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Get image "Type" with identify ?

Post 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.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Get image "Type" with identify ?

Post 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"; 

?> 
Bingo
Posts: 24
Joined: 2007-03-26T03:43:14-07:00

Re: Get image "Type" with identify ?

Post by Bingo »

Oh OK you just meant extracting the information from the "verbose" output.
I can do that.
Thanks for your help guys !
Post Reply