Skip to main content

Convert between color formats: hex, RGB, HSL, HSV, CMYK, and named CSS colors

Project description

philiprehberger-color-convert

Tests PyPI version License

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()

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)

Development

pip install -e .
python -m pytest tests/ -v

License

MIT

Project details


Download files

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

Source Distribution

philiprehberger_color_convert-0.1.7.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

philiprehberger_color_convert-0.1.7-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_color_convert-0.1.7.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_color_convert-0.1.7.tar.gz
Algorithm Hash digest
SHA256 923e3fee260f4d6dca0b8d3d00f13e6d13db02f6b591154ff3121448303d1886
MD5 4c66607e6dd94b6b4cc06b9409c49842
BLAKE2b-256 4bd43782f1d552549ef825b2108b01338988d97374944940aeb2b829d146cc1d

See more details on using hashes here.

File details

Details for the file philiprehberger_color_convert-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_color_convert-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 70410be501bc3d89ee53b5546f29efb6bc0d394ffdb7a508dfbbafc07a51fbf3
MD5 324a03bcc77c756f70b015aa5e35e77c
BLAKE2b-256 023d38af2d82d7b0982257c1e4af5ea78151e12adf15e7d0e7387f7ae2d35f7d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page