Page 1 of 1

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

Posted: 2018-10-08T11:05:20-07:00
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!

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

Posted: 2018-10-08T11:29:15-07:00
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

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

Posted: 2018-10-08T13:45:10-07:00
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!

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

Posted: 2018-10-08T14:26:26-07:00
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.