趣味工具
转换颜色格式并计算 WCAG 对比度
GET
公开访问/color/{hex}命令行客户端(curl、wget、HTTPie,且未明确要求 JSON 或 SVG)得到 text/plain,可用 format=json、format=text、format=svg 覆盖;color=0 关闭 ANSI 颜色。 format=svg 返回原色、更亮、更暗和补色的色板,公开缓存 1 天。对比度按不透明 RGB 计算。 访问类别:匿名 API,可携带 Token 使用独立额度
请求参数
hexpath必填- 3、4、6 或 8 位十六进制,可带 #
- string · 3、4、6 或 8 位十六进制,可带 # · 最短:3 字符 · 最长:9 字符
againstquery- 可选的对照色
- string · 可选的对照色 · 最短:3 字符 · 最长:9 字符
响应
200 颜色分量、CSS 写法、相对亮度和 WCAG 对比度。format=svg 时为色板。
application/json
{
"type": "object",
"properties": {
"hex": {
"type": "string"
},
"rgb": {
"type": "object",
"properties": {
"r": {
"type": "number"
},
"g": {
"type": "number"
},
"b": {
"type": "number"
},
"a": {
"type": "number"
}
},
"required": [
"r",
"g",
"b",
"a"
]
},
"hsl": {
"type": "object",
"properties": {
"h": {
"type": "number"
},
"s": {
"type": "number"
},
"l": {
"type": "number"
}
},
"required": [
"h",
"s",
"l"
]
},
"css": {
"type": "object",
"properties": {
"hex": {
"type": "string"
},
"rgb": {
"type": "string"
},
"hsl": {
"type": "string"
}
},
"required": [
"hex",
"rgb",
"hsl"
]
},
"luminance": {
"type": "number"
},
"contrast": {
"type": "object",
"properties": {
"black": {
"type": "object",
"properties": {
"ratio": {
"type": "number"
},
"aa": {
"type": "boolean"
},
"aaa": {
"type": "boolean"
},
"aaLarge": {
"type": "boolean"
},
"aaaLarge": {
"type": "boolean"
}
},
"required": [
"ratio",
"aa",
"aaa",
"aaLarge",
"aaaLarge"
]
},
"white": {
"type": "object",
"properties": {
"ratio": {
"type": "number"
},
"aa": {
"type": "boolean"
},
"aaa": {
"type": "boolean"
},
"aaLarge": {
"type": "boolean"
},
"aaaLarge": {
"type": "boolean"
}
},
"required": [
"ratio",
"aa",
"aaa",
"aaLarge",
"aaaLarge"
]
},
"against": {
"type": [
"object",
"null"
],
"properties": {
"ratio": {
"type": "number"
},
"aa": {
"type": "boolean"
},
"aaa": {
"type": "boolean"
},
"aaLarge": {
"type": "boolean"
},
"aaaLarge": {
"type": "boolean"
}
},
"required": [
"ratio",
"aa",
"aaa",
"aaLarge",
"aaaLarge"
]
}
},
"required": [
"black",
"white",
"against"
]
}
},
"required": [
"hex",
"rgb",
"hsl",
"css",
"luminance",
"contrast"
],
"additionalProperties": {}
}image/svg+xml
{
"type": "string"
}400 请求校验或执行失败
application/json
{
"type": "object",
"properties": {
"error": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"message": {
"type": "string"
},
"issues": {
"type": "array",
"items": {
"type": "object",
"properties": {
"location": {
"type": "string",
"enum": [
"body",
"query",
"path",
"header"
]
},
"field": {
"type": "string"
},
"code": {
"type": "string"
},
"message": {
"type": "string"
}
},
"required": [
"location",
"field",
"code",
"message"
]
}
}
},
"required": [
"code",
"message"
]
}
},
"required": [
"error"
]
}401 凭据无效、停用、过期或缺少所需 Token
application/json
{
"type": "object",
"properties": {
"error": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"message": {
"type": "string"
},
"issues": {
"type": "array",
"items": {
"type": "object",
"properties": {
"location": {
"type": "string",
"enum": [
"body",
"query",
"path",
"header"
]
},
"field": {
"type": "string"
},
"code": {
"type": "string"
},
"message": {
"type": "string"
}
},
"required": [
"location",
"field",
"code",
"message"
]
}
}
},
"required": [
"code",
"message"
]
}
},
"required": [
"error"
]
}403 需要管理员 Token
application/json
{
"type": "object",
"properties": {
"error": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"message": {
"type": "string"
},
"issues": {
"type": "array",
"items": {
"type": "object",
"properties": {
"location": {
"type": "string",
"enum": [
"body",
"query",
"path",
"header"
]
},
"field": {
"type": "string"
},
"code": {
"type": "string"
},
"message": {
"type": "string"
}
},
"required": [
"location",
"field",
"code",
"message"
]
}
}
},
"required": [
"code",
"message"
]
}
},
"required": [
"error"
]
}413 请求体过大
application/json
{
"type": "object",
"properties": {
"error": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"message": {
"type": "string"
},
"issues": {
"type": "array",
"items": {
"type": "object",
"properties": {
"location": {
"type": "string",
"enum": [
"body",
"query",
"path",
"header"
]
},
"field": {
"type": "string"
},
"code": {
"type": "string"
},
"message": {
"type": "string"
}
},
"required": [
"location",
"field",
"code",
"message"
]
}
}
},
"required": [
"code",
"message"
]
}
},
"required": [
"error"
]
}415 请求内容类型无效
application/json
{
"type": "object",
"properties": {
"error": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"message": {
"type": "string"
},
"issues": {
"type": "array",
"items": {
"type": "object",
"properties": {
"location": {
"type": "string",
"enum": [
"body",
"query",
"path",
"header"
]
},
"field": {
"type": "string"
},
"code": {
"type": "string"
},
"message": {
"type": "string"
}
},
"required": [
"location",
"field",
"code",
"message"
]
}
}
},
"required": [
"code",
"message"
]
}
},
"required": [
"error"
]
}429 请求过于频繁,Retry-After 为建议等待秒数;匿名额度及认证保护在各 Cloudflare 地点近似计数,Token 业务额度使用 D1 原子计数
application/json
{
"type": "object",
"properties": {
"error": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"message": {
"type": "string"
},
"issues": {
"type": "array",
"items": {
"type": "object",
"properties": {
"location": {
"type": "string",
"enum": [
"body",
"query",
"path",
"header"
]
},
"field": {
"type": "string"
},
"code": {
"type": "string"
},
"message": {
"type": "string"
}
},
"required": [
"location",
"field",
"code",
"message"
]
}
}
},
"required": [
"code",
"message"
]
}
},
"required": [
"error"
]
}500 内部执行失败
application/json
{
"type": "object",
"properties": {
"error": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"message": {
"type": "string"
},
"issues": {
"type": "array",
"items": {
"type": "object",
"properties": {
"location": {
"type": "string",
"enum": [
"body",
"query",
"path",
"header"
]
},
"field": {
"type": "string"
},
"code": {
"type": "string"
},
"message": {
"type": "string"
}
},
"required": [
"location",
"field",
"code",
"message"
]
}
}
},
"required": [
"code",
"message"
]
}
},
"required": [
"error"
]
}在线调试
调用示例
curl -X GET 'https://evax.top/color/336699'