Skip to main content

color-convert

PyPI version Python License Documentation Status

颜色格式转换工具,支持 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

MIT License

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

color_convert-1.4.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

color_convert-1.4-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

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

Hashes for color_convert-1.4.tar.gz
Algorithm Hash digest
SHA256 2358624d13338da59349edd9e5e1c695ea623c07822b9d89fefeb96d2ad0c089
MD5 adee432bba5826fab9f6d8371154bd95
BLAKE2b-256 a4930c5d3ef2885f28f102894fcbb22cdbda4915b4e95fffe67c1cd4e84f7c94

See more details on using hashes here.

Provenance

The following attestation bundles were made for color_convert-1.4.tar.gz:

Publisher: workflow.yml on zhenzi0322-package/color-convert

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for color_convert-1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cf241c6576f9561d710ac7f3befe9bcf844154beb2dd7e7866ae759730f432dd
MD5 9611c24a80bd1db35ebe26c2be11dd75
BLAKE2b-256 fcdd01bbc601a84ce916abaf3d548f05b3e25431b97c84b3dbd2dde95c554f6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for color_convert-1.4-py3-none-any.whl:

Publisher: workflow.yml on zhenzi0322-package/color-convert

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.4 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page