Unable to parse identify output

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
happycloud
Posts: 1
Joined: 2012-11-11T22:30:34-07:00
Authentication code: 67789

Unable to parse identify output

Post by happycloud »

We are using the NodeJS imagemagick module and need to parse the dump of identify. Recently, I think, the output of identify has broken the node modules (there are a few and they all broke) because the dump is not parseable. I have tested this with IM 6.7.7-6 and multiple images (mostly pngs seem to be at issue - but not consistent).

Here's the problematic section of the ouptut

Code: Select all

 Image statistics:',
    Overall:',
      min: 52 (0.203922)',
      max: 255 (1)',
      mean: 197.2 (0.773333)',
      standard deviation: 70.187 (0.275243)',
      kurtosis: -0.83089',
      skewness: -0.803467',
  Colors: 123',
  Histogram:',
       973: (107,108, 52) #6B6C34 srgb(107,108,52)',
        70: (108,105, 55) #6C6937 srgb(108,105,55)',
         2: (110,107, 58) #6E6B3A srgb(110,107,58)',
         2: (112,109, 60) #706D3C srgb(112,109,60)',
         .... more here
  Colormap: 129',
      0: (107,108, 52) #6B6C34 srgb(107,108,52)',
      1: (232,232,208) #E8E8D0 srgb(232,232,208)',
      2: (167,178, 80) #A7B250 srgb(167,178,80)',
      3: (166,164,134) #A6A486 srgb(166,164,134)',
      4: (114,111, 63) #726F3F srgb(114,111,63)',
      5: (209,210,161) #D1D2A1 srgb(209,210,161)',
      ... mohre here all the way to 128 in this case - 129 total
As you can see, this mostly reads like a multi depth array for all fields except the colormap - the "129" string effectively breaks this pattern - I assume the 0-128 fields belong to the colormap but in this file they do not - they belong as root entries. It's like the '129' string should not be there.

Suggestions?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Unable to parse identify output

Post by anthony »

I would say it is a valid point. Though you could parse the tree using the indent instead.

Do you have a specific identify part that you are interested in? I usually parse identify output for specific components by looking for the start tag, and exiting when indent is not right, or the next tag (though that can be fragile.

For example from IM Examples... Comparing images..
This gets min,max,average colors from a resulting grayscale image. Though it does go 1 line too far.

convert image1 image2 -compose Difference -composite \
-colorspace gray -verbose info: |\
sed -n '/statistics:/,/^ [^ ]/ p'
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Unable to parse identify output

Post by magick »

The output of identify is meant to be "human readable." For the colormap entry, the number that follows is the number of entries in the colormap. However, this information is already available as the Colors tag. We'll remove the value to ensure a consistent format making it both human and machine readable.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Unable to parse identify output

Post by fmw42 »

I am not sure that is a good idea? Is it possible that the number of entries in the colormap may be different from the number of colors?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Unable to parse identify output

Post by magick »

Right, we would need to present it as a separate tag.
Post Reply