Convert between color formats: hex, RGB, HSL, HSV, CMYK, and named CSS colors
Project description
philiprehberger-color-convert
Convert between color formats: hex, RGB, HSL, HSV, CMYK, and named CSS colors.
Installation
pip install philiprehberger-color-convert
Usage
from philiprehberger_color_convert import Color
# Create from hex
c = Color("#ff6b35")
# Create from CSS named color
c = Color("tomato")
# Create from RGB string
c = Color("rgb(255, 107, 53)")
# Create from another Color
c2 = Color(c)
Factory Methods
c = Color.from_rgb(255, 107, 53)
c = Color.from_hsl(20, 100, 60)
c = Color.from_hsv(20, 79, 100)
c = Color.from_cmyk(0, 58, 79, 0)
Format Properties
c = Color("#ff6b35")
c.rgb # (255, 107, 53)
c.hex # "#ff6b35"
c.hsl # (16, 100, 60)
c.hsv # (16, 79, 100)
c.cmyk # (0, 58, 79, 0)
Manipulation
c = Color("#ff6b35")
lighter = c.lighten(20)
darker = c.darken(20)
more = c.saturate(10)
less = c.desaturate(10)
comp = c.complement()
inv = c.invert()
Chaining
# Each method returns a new Color — chain freely
warm = Color("#3498db").desaturate(20).lighten(10)
print(warm.hex)
Palette Generation
c = Color("#ff6b35")
c.analogous() # [Color, Color, Color]
c.triadic() # [Color, Color, Color]
c.split_complementary() # [Color, Color, Color]
Contrast Ratio
white = Color("#ffffff")
black = Color("#000000")
white.contrast_ratio(black) # 21.0
API
| Method / Property | Description |
|---|---|
Color(value) |
Create from hex, RGB string, CSS name, or Color |
Color.from_rgb(r, g, b) |
Create from RGB values (0-255) |
Color.from_hsl(h, s, l) |
Create from HSL (h: 0-360, s/l: 0-100) |
Color.from_hsv(h, s, v) |
Create from HSV (h: 0-360, s/v: 0-100) |
Color.from_cmyk(c, m, y, k) |
Create from CMYK (0-100 each) |
.rgb |
RGB tuple (r, g, b) |
.hex |
Hex string "#rrggbb" |
.hsl |
HSL tuple (h, s, l) |
.hsv |
HSV tuple (h, s, v) |
.cmyk |
CMYK tuple (c, m, y, k) |
.lighten(percent) |
Return lighter Color |
.darken(percent) |
Return darker Color |
.saturate(percent) |
Return more saturated Color |
.desaturate(percent) |
Return less saturated Color |
.complement() |
Return complementary Color |
.invert() |
Return inverted Color |
.analogous() |
List of 3 analogous Colors |
.triadic() |
List of 3 triadic Colors |
.split_complementary() |
List of 3 split-complementary Colors |
.contrast_ratio(other) |
WCAG contrast ratio (float) |
css_color_names() |
Sorted list of all 148 supported CSS color names |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
License
Project details
Release history Release notifications | RSS feed
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 philiprehberger_color_convert-0.1.9.tar.gz.
File metadata
- Download URL: philiprehberger_color_convert-0.1.9.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b87bfac4ce49d4c7d81386f872fe0fce68d0175f8c7dc3a336bceaf1edd35ab
|
|
| MD5 |
c5d0d957672e9570bec6a9a256383652
|
|
| BLAKE2b-256 |
27312cfb0cf92a03c0b5c66768dbb69b713c49a23d96a5c016fa9d7ee35c5dfe
|
File details
Details for the file philiprehberger_color_convert-0.1.9-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_color_convert-0.1.9-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bee5778e0e709f18f6dfa11c28abe0c8ca002934095770399603ef70d1e13305
|
|
| MD5 |
b6116aa81e4d75bca2dd8c18578a8c02
|
|
| BLAKE2b-256 |
3baab4b03a9289e6273816ef7041325a213ac2ffc0c670b51208865d72fedbd5
|