color-convert
颜色格式转换工具,支持 HEX、RGB、RGBA、HSL、HSV、CMYK、十进制等多种颜色格式之间的相互转换。
安装
pip install color-convert
支持的颜色格式
| 格式 | 示例 |
|---|---|
| HEX(十六进制) | #fff000 |
| RGB | rgb(255, 240, 0) |
| RGBA | rgba(255, 240, 0, 1) |
| HSL | hsl(56, 100%, 50%) |
| HSV | hsv(56, 100%, 100%) |
| CMYK | cmyk(0%, 6%, 100%, 0%) |
| Decimal(十进制) | 16711680 |
使用示例
十六进制 → RGB
from color_convert import color
rgb = color.hex_to_rgb('#fff000')
print(rgb) # rgb(255,240,0)
十六进制 → RGBA
from color_convert import color
rgba = color.hex_to_rgba('#fff000')
print(rgba) # rgba(255,240,0,1)
rgba = color.hex_to_rgba('#fff000a8')
print(rgba) # rgba(255,240,0,0.66)
十六进制 → HSL
from color_convert import color
hsl = color.hex_to_hsl('#fff000')
print(hsl) # hsl(56, 100%, 50%)
十六进制 → HSV
from color_convert import color
hsv = color.hex_to_hsv('#fff000')
print(hsv) # hsv(56, 100%, 100%)
十进制 → 十六进制
from color_convert import color
hex_val = color.ten_to_hex(16711680)
print(hex_val) # #ff0000
十进制 → RGBA
from color_convert import color
rgba = color.ten_to_rgb(16711680)
print(rgba) # rgba(255,0,0,1)
RGB → 十六进制
from color_convert import color
hex_val = color.rgb_to_hex(255, 240, 0)
print(hex_val) # #fff000
RGBA → 十六进制
from color_convert import color
hex_val = color.rgba_to_hex(255, 240, 0, 0.66)
print(hex_val) # #fff000a8
RGB → HSL
from color_convert import color
hsl = color.rgb_to_hsl(255, 240, 0)
print(hsl) # hsl(56, 100%, 50%)
HSL → RGB
from color_convert import color
rgb = color.hsl_to_rgb(56, 100, 50)
print(rgb) # rgb(255, 238, 0)
RGB → HSV
from color_convert import color
hsv = color.rgb_to_hsv(255, 240, 0)
print(hsv) # hsv(56, 100%, 100%)
HSV → RGB
from color_convert import color
rgb = color.hsv_to_rgb(56, 100, 100)
print(rgb) # rgb(255, 238, 0)
RGB → CMYK
from color_convert import color
cmyk = color.rgb_to_cmyk(255, 240, 0)
print(cmyk) # cmyk(0%, 6%, 100%, 0%)
CMYK → RGB
from color_convert import color
rgb = color.cmyk_to_rgb(0, 6, 100, 0)
print(rgb) # rgb(255, 240, 0)
API 参考
| 函数名 | 说明 | 参数 | 返回值示例 |
|---|---|---|---|
hex_to_rgb(hex) |
十六进制 → RGB | hex: 如 #fff000 |
rgb(255,240,0) |
hex_to_rgba(hex_str) |
十六进制 → RGBA(支持带透明度) | hex_str: 如 #fff000 或 #fff000a8 |
rgba(255,240,0,1) |
hex_to_hsl(hex_str) |
十六进制 → HSL | hex_str: 如 #fff000 |
hsl(56, 100%, 50%) |
hex_to_hsv(hex_str) |
十六进制 → HSV | hex_str: 如 #fff000 |
hsv(56, 100%, 100%) |
ten_to_hex(num) |
十进制 → 十六进制 | num: 如 16711680 |
#ff0000 |
ten_to_rgb(num) |
十进制 → RGBA | num: 如 16711680 |
rgba(255,0,0,1) |
rgb_to_hex(r, g, b) |
RGB → 十六进制 | r, g, b: 0-255 |
#fff000 |
rgba_to_hex(r, g, b, a) |
RGBA → 十六进制(带透明度) | r, g, b: 0-255, a: 0-1 |
#fff000a8 |
rgb_to_hsl(r, g, b) |
RGB → HSL | r, g, b: 0-255 |
hsl(56, 100%, 50%) |
hsl_to_rgb(h, s, l) |
HSL → RGB | h: 0-360, s: 0-100, l: 0-100 |
rgb(255, 238, 0) |
rgb_to_hsv(r, g, b) |
RGB → HSV | r, g, b: 0-255 |
hsv(56, 100%, 100%) |
hsv_to_rgb(h, s, v) |
HSV → RGB | h: 0-360, s: 0-100, v: 0-100 |
rgb(255, 238, 0) |
rgb_to_cmyk(r, g, b) |
RGB → CMYK | r, g, b: 0-255 |
cmyk(0%, 6%, 100%, 0%) |
cmyk_to_rgb(c, m, y, k) |
CMYK → RGB | c, m, y, k: 0-100 |
rgb(255, 240, 0) |
License
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file color_convert-1.4.tar.gz.
File metadata
- Download URL: color_convert-1.4.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2358624d13338da59349edd9e5e1c695ea623c07822b9d89fefeb96d2ad0c089
|
|
| MD5 |
adee432bba5826fab9f6d8371154bd95
|
|
| BLAKE2b-256 |
a4930c5d3ef2885f28f102894fcbb22cdbda4915b4e95fffe67c1cd4e84f7c94
|
Provenance
The following attestation bundles were made for color_convert-1.4.tar.gz:
Publisher:
workflow.yml on zhenzi0322-package/color-convert
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
color_convert-1.4.tar.gz -
Subject digest:
2358624d13338da59349edd9e5e1c695ea623c07822b9d89fefeb96d2ad0c089 - Sigstore transparency entry: 2247138900
- Sigstore integration time:
-
Permalink:
zhenzi0322-package/color-convert@586d5d27dc0598546e43a0670721c74a361f1866 -
Branch / Tag:
refs/tags/v1.4 - Owner: https://github.com/zhenzi0322-package
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@586d5d27dc0598546e43a0670721c74a361f1866 -
Trigger Event:
push
-
Statement type:
File details
Details for the file color_convert-1.4-py3-none-any.whl.
File metadata
- Download URL: color_convert-1.4-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf241c6576f9561d710ac7f3befe9bcf844154beb2dd7e7866ae759730f432dd
|
|
| MD5 |
9611c24a80bd1db35ebe26c2be11dd75
|
|
| BLAKE2b-256 |
fcdd01bbc601a84ce916abaf3d548f05b3e25431b97c84b3dbd2dde95c554f6f
|
Provenance
The following attestation bundles were made for color_convert-1.4-py3-none-any.whl:
Publisher:
workflow.yml on zhenzi0322-package/color-convert
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
color_convert-1.4-py3-none-any.whl -
Subject digest:
cf241c6576f9561d710ac7f3befe9bcf844154beb2dd7e7866ae759730f432dd - Sigstore transparency entry: 2247139772
- Sigstore integration time:
-
Permalink:
zhenzi0322-package/color-convert@586d5d27dc0598546e43a0670721c74a361f1866 -
Branch / Tag:
refs/tags/v1.4 - Owner: https://github.com/zhenzi0322-package
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@586d5d27dc0598546e43a0670721c74a361f1866 -
Trigger Event:
push
-
Statement type: