ColorLab — Color Tool
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.
Commands
| Command | Description |
|---|
| INLINECODE2 | Convert hex color to RGB values |
| INLINECODE3 |
Convert RGB values (0-255) to hex |
|
contrast <hex1> <hex2> | Calculate WCAG 2.0 contrast ratio with AA/AAA pass/fail ratings |
|
palette <hex> [count] | 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 <hex> | Find the closest named CSS color (from ~50 common colors) |
Examples
CODEBLOCK0
Notes
- - Hex colors accept
# prefix (optional) and 3-digit shorthand (#F00 → #FF0000) - WCAG contrast checks report AA/AAA compliance for normal and large text
- Palette output includes ANSI 24-bit color swatches (requires a modern terminal)
- Color naming uses Euclidean distance in RGB space against ~50 common CSS color names
ColorLab — 颜色工具
转换颜色、生成调色板、检查WCAG对比度,并查找最接近的CSS颜色名称。使用printf和awk进行计算,终端输出中带有ANSI 24位色块。
命令
| 命令 | 描述 |
|---|
| hex-to-rgb <hex> | 将十六进制颜色转换为RGB值 |
| rgb-to-hex <r> <g> <b> |
将RGB值(0-255)转换为十六进制 |
| contrast
| 计算WCAG 2.0对比度,并给出AA/AAA通过/失败评级 |
| palette [count] | 生成颜色的较亮和较暗变体(默认:每个方向5个) |
| random [count] | 生成随机颜色,包含十六进制和RGB值(默认:1个) |
| name | 查找最接近的命名CSS颜色(来自约50种常见颜色) |
示例
bash
将十六进制转换为RGB
colorlab hex-to-rgb #FF5733 # → rgb(255, 87, 51)
将RGB转换为十六进制
colorlab rgb-to-hex 255 87 51 # → #FF5733
检查无障碍对比度
colorlab contrast #FFFFFF #000000
→ 21.00:1,WCAG AA/AAA 全部通过
生成调色板
colorlab palette #3498db 3
→ 显示3个较暗 + 基础色 + 3个较亮变体,附带色块
随机颜色
colorlab random 5
查找最接近的CSS颜色名称
colorlab name #e74c3c # → 深红色
备注
- - 十六进制颜色接受#前缀(可选)和3位简写(#F00 → #FF0000)
- WCAG对比度检查报告正常文本和大文本的AA/AAA合规性
- 调色板输出包含ANSI 24位色块(需要现代终端)
- 颜色命名使用RGB空间中的欧几里得距离,针对约50种常见CSS颜色名称