Convert colors, generate palettes, check WCAG contrast ratios, and find closest CSS color names. Uses printf and awk for calculations, with ANSI 24-bit color swatches in terminal output.
| Command | Description |
|---|---|
| --------- | ------------- |
hex-to-rgb | Convert hex color to RGB values |
rgb-to-hex | Convert RGB values (0-255) to hex |
contrast | Calculate WCAG 2.0 contrast ratio with AA/AAA pass/fail ratings |
palette | Generate lighter and darker variants of a color (default: 5 each direction) |
random [count] | Generate random colors with hex and RGB values (default: 1) |
name | Find the closest named CSS color (from ~50 common colors) |
# Convert hex to RGB
colorlab hex-to-rgb "#FF5733" # → rgb(255, 87, 51)
# Convert RGB to hex
colorlab rgb-to-hex 255 87 51 # → #FF5733
# Check contrast for accessibility
colorlab contrast "#FFFFFF" "#000000"
# → 21.00:1, WCAG AA/AAA all pass
# Generate a palette
colorlab palette "#3498db" 3
# → Shows 3 darker + base + 3 lighter variants with color swatches
# Random colors
colorlab random 5
# Find closest CSS color name
colorlab name "#e74c3c" # → Crimson
# prefix (optional) and 3-digit shorthand (#F00 → #FF0000)共 2 个版本