Export the palette of an 8-bit color image to an image.

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
TheAlmightyGuru
Posts: 4
Joined: 2017-08-14T11:27:10-07:00
Authentication code: 1151

Export the palette of an 8-bit color image to an image.

Post by TheAlmightyGuru »

I'm trying to extract the full palette table of an image using an 8-bit color depth. I have tried variations involving "-unique-colors" and "histogram:info:-", but both of these options reorder the color table and ignore duplicate colors in the table.

My ultimate goal is to create a color palette swatch in the shape of a 16x16 grid like in this mockup: http://www.thealmightyguru.com/Imagemag ... xample.png

I'm using Imagemagick 7 through a Windows 7 command line. Any help would be appreciated!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Export the palette of an 8-bit color image to an image.

Post by snibgo »

The only method I know is "identify -verbose" and process the text. I show a Windows BAT script for this at http://im.snibgo.com/ckbkClut.htm#getColormap.bat
snibgo's IM pages: im.snibgo.com
TheAlmightyGuru
Posts: 4
Joined: 2017-08-14T11:27:10-07:00
Authentication code: 1151

Re: Export the palette of an 8-bit color image to an image.

Post by TheAlmightyGuru »

I had to make some minor changes to have it work with the magick command of IM 7, but it did what I wanted it to do. I'll work at altering the output into the 16x16 image that I want.

Thanks for the reply snibgo. I have come across your site numerous times in the past looking for complex use of Imagemagick, and it's really impressive!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Export the palette of an 8-bit color image to an image.

Post by snibgo »

The script makes an image 256x1 pixels. Changing the script to directly make a 16x16 image is possible but tricky. Converting a 256x1 to 16x16 is easy:

Code: Select all

magick in.png -crop 16x1@ -append +repage -scale 1000% out.png
I've also scaled to make the pixels more visible.
snibgo's IM pages: im.snibgo.com
Post Reply