Script to Create Colour Chip Layers in Photoshop
I would like to automate the process of adding colour chip layers to my images. The images will only ever contain between 2–16 colours, and are pixel-perfect. I would like to be able to automatically scan the flat layer containing the image, and create rectangle layers for each colour in the image resulting in something like the below:

I thought it could be possible using index colour to create a swatch palette, but not sure how I could then create the rectangles automatically using the colours in the saved palette?. Alternatively, can a script just scan the layer for every variant of colour since I can be sure there will only ever be max 16?
Is this possible? Or wishful thinking?
