{"id":26540496,"url":"https://github.com/mccutchen/palettor","last_synced_at":"2026-03-05T19:10:28.472Z","repository":{"id":47071494,"uuid":"39281910","full_name":"mccutchen/palettor","owner":"mccutchen","description":"Yet another way to extract the color palette from an image using k-means clustering","archived":false,"fork":false,"pushed_at":"2023-03-17T17:32:19.000Z","size":317,"stargazers_count":19,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-06-19T02:11:06.494Z","etag":null,"topics":["color-palette","golang","image-processing","kmeans-clustering"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/mccutchen/palettor","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mccutchen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-07-18T01:07:51.000Z","updated_at":"2024-05-20T14:15:48.000Z","dependencies_parsed_at":"2024-06-19T01:55:33.617Z","dependency_job_id":"086d156b-35f7-4449-b9e2-f8216013216d","html_url":"https://github.com/mccutchen/palettor","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mccutchen%2Fpalettor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mccutchen%2Fpalettor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mccutchen%2Fpalettor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mccutchen%2Fpalettor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mccutchen","download_url":"https://codeload.github.com/mccutchen/palettor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244890102,"owners_count":20527030,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["color-palette","golang","image-processing","kmeans-clustering"],"created_at":"2025-03-22T00:33:43.917Z","updated_at":"2026-03-05T19:10:23.414Z","avatar_url":"https://github.com/mccutchen.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Palettor\n\nYet another way to extract dominant colors from an image using [k-means clustering][1].\n\n[![Documentation](https://pkg.go.dev/badge/github.com/mccutchen/palettor)](https://pkg.go.dev/github.com/mccutchen/palettor)\n[![Build status](https://github.com/mccutchen/palettor/actions/workflows/test.yaml/badge.svg)](https://github.com/mccutchen/palettor/actions/workflows/test.yaml)\n[![Code coverage](https://codecov.io/gh/mccutchen/palettor/branch/main/graph/badge.svg)](https://codecov.io/gh/mccutchen/palettor)\n[![Go report card](http://goreportcard.com/badge/github.com/mccutchen/palettor)](https://goreportcard.com/report/github.com/mccutchen/palettor)\n\n\n## Tests\n\n### Unit tests\n\n```\nmake test\n```\n\n### Benchmarks\n\n```\nmake benchmark\n```\n\n\n## Usage as a library\n\n```\ngo get -u github.com/mccutchen/palettor\n```\n\n```go\npackage main\n\nimport (\n    \"image\"\n    _ \"image/gif\"\n    _ \"image/jpeg\"\n    _ \"image/png\"\n    \"log\"\n    \"os\"\n\n    \"github.com/mccutchen/palettor\"\n    \"github.com/nfnt/resize\"\n)\n\nfunc main() {\n    // Read an image from STDIN\n    originalImg, _, err := image.Decode(os.Stdin)\n    if err != nil {\n        log.Fatal(err)\n    }\n\n    // Reduce it to a manageable size\n    img := resize.Thumbnail(200, 200, originalImg, resize.Lanczos3)\n\n    // Extract the 3 most dominant colors, halting the clustering algorithm\n    // after 100 iterations if the clusters have not yet converged.\n    k := 3\n    maxIterations := 100\n    palette, err := palettor.Extract(k, maxIterations, img)\n\n    // Err will only be non-nil if k is larger than the number of pixels in the\n    // input image.\n    if err != nil {\n        log.Fatalf(\"image too small\")\n    }\n\n    // Palette is a mapping from color to the weight of that color's cluster,\n    // which can be used as an approximation for that color's relative\n    // dominance\n    for _, color := range palette.Colors() {\n        log.Printf(\"color: %v; weight: %v\", color, palette.Weight(color))\n    }\n\n    // Example output:\n    // 2015/07/19 10:27:52 color: {44 120 135}; weight: 0.17482142857142857\n    // 2015/07/19 10:27:52 color: {140 103 150}; weight: 0.39558035714285716\n    // 2015/07/19 10:27:52 color: {189 144 118}; weight: 0.42959821428571426\n}\n```\n\n## The `palettor` command line application\n\nAn example command line application is provided, which reads an input image and\neither a) overlays the dominant palette on the bottom of the image or b)\ngenerates a JSON representation of the dominant color palette:\n\n```\n$ go get -u github.com/mccutchen/palettor/cmd/palettor\n\n$ palettor -help\nUsage: palettor [OPTIONS] [INPUT]\n\n  -json\n        Output color palette in JSON format\n  -k int\n        Palette size (default 3)\n  -max int\n        Maximum k-means iterations (default 500)\n\n$ cat /Library/Desktop\\ Pictures/Beach.jpg | palettor -json | jq .\n[\n  {\n    \"color\": {\n      \"R\": 70,\n      \"G\": 134,\n      \"B\": 154,\n      \"A\": 255\n    },\n    \"weight\": 0.19080357142857143\n  },\n  {\n    \"color\": {\n      \"R\": 175,\n      \"G\": 187,\n      \"B\": 183,\n      \"A\": 255\n    },\n    \"weight\": 0.26852678571428573\n  },\n  {\n    \"color\": {\n      \"R\": 210,\n      \"G\": 208,\n      \"B\": 199,\n      \"A\": 255\n    },\n    \"weight\": 0.5406696428571428\n  }\n]\n```\n\n\n[1]: https://en.wikipedia.org/wiki/K-means_clustering#Standard_algorithm\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmccutchen%2Fpalettor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmccutchen%2Fpalettor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmccutchen%2Fpalettor/lists"}