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)".

1 Answer 1

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
1
  • That looks like it's listing every single pixel, which isn't what I want.
    – Rena
    Commented Dec 23, 2019 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.