0

I want identify -verbose myImage.jpg to output all color values in hex format.

I've found this answer but it only works for a single color; eg:

$ identify -verbose -format '%[hex:u]\n' myImage.jpg 
F9CBA9

compared to not specifying a format:

$ identify -verbose myImage.jpg
Image: /home/rena/img/myImage.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Mime type: image/jpeg
  Class: DirectClass
  [...lots more info here...]
  Background color: white
  Border color: srgb(223,223,223)
  [...]
  Version: ImageMagick 7.0.9-5 Q16 x86_64 2019-11-18 https://imagemagick.org

What I want is the latter output, except for properties that list a color to list it in hex, eg "#FFFFFF" and "#DFDFDF" instead of "white" and "srgb(223,223,223)".

Rena
  • 606
  • 7
  • 21

1 Answers1

1

You can use the txt: protocol to write all pixel information in a text format, and pipe the results to the cut utility.

magick myImage.jpg txt:- | cut -d ' ' -f 4

You can also use uniq to remove duplicate hex-color entries.

magick myImage.jpg txt:- | cut -d ' ' -f 4 | uniq
emcconville
  • 23,800
  • 4
  • 50
  • 66