Extract Dominant Colors From Images
go install github.com/james-see/swatchify@latest
brew install james-see/tap/swatchify
→ github.com/james-see/swatchify/releases
$ swatchify photo.jpg #131014 #7673AD #73500A #B68296 #44353B $ swatchify logo.png -n 8 --json { "image": "logo.png", "colors": [ {"hex": "#FF0000", "percentage": 34.5}, {"hex": "#00FF00", "percentage": 21.0}, ... ] } $ swatchify brand.png --png palette.png --show → Opens palette image with hex labels
Run as HTTP server. POST images, get JSON colors back. CORS enabled.
Import as a package. ExtractFromFile(), ExtractFromImage(), GeneratePalette().
Sub-300ms processing. Automatic image downscaling for speed.
Advanced clustering algorithm for accurate dominant color extraction.
Machine-readable output with hex values and percentage weights.
Generate visual palettes with proportional color blocks and hex labels.
Exclude white, black, or similar colors. Control minimum contrast.
Single binary for macOS, Linux, and Windows. ARM64 supported.
$ swatchify serve --port 8080 🎨 Swatchify server starting on http://localhost:8080 $ curl -X POST -F "image=@photo.jpg" localhost:8080/extract { "success": true, "colors": [ {"hex": "#FF0000", "percentage": 34.5}, {"hex": "#00FF00", "percentage": 21.0} ] } $ curl -X POST -F "image=@photo.jpg" -F "colors=8" \ -F "exclude_white=true" localhost:8080/extract
import "github.com/james-see/swatchify/pkg/swatchify" // Extract colors from file colors, err := swatchify.ExtractFromFile("photo.jpg", nil) // With options opts := &swatchify.Options{ NumColors: 8, ExcludeWhite: true, } colors, _ := swatchify.ExtractFromFile("photo.jpg", opts) // Generate palette swatchify.GeneratePalette(colors, "palette.png", nil)
-n, --colors Number of colors (default: 5) --json Output as JSON --png Generate palette PNG --exclude-white Skip near-white colors --exclude-black Skip near-black colors --min-contrast Min distance between colors --show Open palette after creation --quality 0-100, accuracy vs speed --width Palette width (default: 1000) --height Palette height (default: 200) serve --port Start API server on port