Getting standard Hex colors

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
Posts: 2
Joined: 2018-05-10T20:50:57-07:00
Authentication code: 1152

Getting standard Hex colors

Post by carol1988 » 2018-05-10T20:53:53-07:00

I've been trying to extract colors from an image, well, various images.

I would like to get standard HTML colors, #000000 - #FFFFFF , but I'm getting all sorts of things, like

To get the color in the upper left corner, I'm using the command:

convert input.gif -crop 1x1+0+0 txt:color color.txt

I've tried using -colors and -colormap, but it hasn't helped.

What can I do to get it in the format: #FFFFFF

User avatar
Posts: 23047
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Getting standard Hex colors

Post by fmw42 » 2018-05-10T21:28:40-07:00

Please, always provide your IM version and platform when asking questions, since syntax may differ. Also provide your exact command line and if possible your images.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at ... f=1&t=9620

For novices, see ... f=1&t=9620 ... essing.php

Code: Select all

convert input.gif -format "%[hex:u.p{0,0}]" info:
Otherwise the txt: format is

x,y (R,G,B) hex srgb(r,g,b)

where x,y is the coordinate, (R,G,B) are the values in the quantum range (for Q16 that would be 0 to 65535), then the hex value, then the last is either r,g,b values or color names.

If you want short hex values then add -depth 8

Code: Select all

convert input.gif -depth 8 -format "%[hex:u.p{0,0}]" info:

Post Reply