Monday, June 5, 2017

Generate Color Palette from Image?


I want to generate a color palette from an image. It's a long, drawn out, tedious process because I have to copy each of the 16-32 colors per image and paste them, making sure I don't forget them which I probably will and have to go back to the image looking for it to put it in my palette image.



I looked online to see if there were any image palette generators, there were, but they don't generate a palette from an image, they try and give you a "similar palette" or something weird like that. I want to generate an image with every single color from the image in a row, like so:


(This is my manually generated palette): manual palette


Something like that, but preferably at 1px height. So-called "palette generators" keep giving me stuff like this for some reason:


enter image description here


What tool(s) can I use to generate an image out of every single color of another image, in a row, like the first picture?



Answer



You can do it with ImageMagick (shown here under Bash):


magick goHGJ.png -depth 8 txt:- | sed -e "1d;s/.* #/#/;s/ .*//" | sort -u

This converts the image to "txt" format, then uses a "sed" script to extract the hex-values for the colors, then "sort -u" to remove duplicates. Here's the result for your test image:



#209020FF
#282830FF
#30C830FF
#403078FF
#505060FF
#5840A0FF
#8050D8FF
#888898FF
#A02000FF
#B090F0FF

#B8B8C8FF
#D03800FF
#E06810FF
#F0B020FF

This is about the same procedure that you hinted at, except it's all done automatically for you without the manual cut-and-paste stuff.


The final "FF" on each entry is the alpha value (fully opaque). For your purposes you can ignore it.


Note that this will give you as many entries as you have colors in your image, so if you start with a photo the list is likely to be pretty long. In such a case you could use the ImageMagick "-colors N" option to reduce the number of colors to some limit, N.


No comments:

Post a Comment

technique - How credible is wikipedia?

I understand that this question relates more to wikipedia than it does writing but... If I was going to use wikipedia for a source for a res...