> For the complete documentation index, see [llms.txt](https://gitbook.testingwaters.in/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.testingwaters.in/lists/reduce-color-palette.md).

# Reduce Color Palette

![](/files/-Lfzt0B6Yzlqd2gMykiM)

{% file src="/files/-Lfzt7icCxvlhpjpJ-fQ" %}

```d
imgDim = Image.Dimensions(img);
pxlWdt = imgDim["width"]/10;
pxlHgt = imgDim["height"]/10;

pxlClr = Image.Pixels(img,pxlWdt,pxlHgt);
r1 = [0,255,0,0,255];
g1 = [0,0,255,0,255];
b1 = [0,0,0,255,255];
c1 = Color.ByARGB(255,r1,g1,b1);
r2 = pxlClr.Red;
g2 = pxlClr.Green;
b2 = pxlClr.Blue;
k1 = Math.Sqrt(Math.Pow((r1-r2<1><2>),2)
+Math.Pow((g1-g2<1><2>),2)+
Math.Pow((b1-b2<1><2>),2));
c2 = List.SortByKey(c1,k1<1><2>)["sorted list"];
c3 = List.FirstItem(c2<1><2>);
i2 = Image.FromPixels(c3);
```

![](/files/-LfzsJZ5fgp9pCujb9lP)

{% file src="/files/-LfztG8FsCghO2O-AeDQ" %}
