Skip to main content

colortool

set of tools to work with different color formats

install from pypi

pip install colortool

examples

>>> from colortool import Color

convert color to different formats

>>> green = Color.from_hex(0x00FF00)
>>> green.css_hex
'#00FF00'
>>> green.rgb_int
(0, 255, 0)
>>> green.rgb_float
(0.0, 1.0, 0.0)
>>> green.hsl
(0.33333333333333, 1.0, 0.5)

create color from different formats

>>> Color.from_css_hex('#00FF00')
Color(0x00FF00)
>>> Color.from_rgb_int((0, 255, 0))
Color(0x00FF00)
>>> Color.from_rgb_float((0.0, 1.0, 0.0))
Color(0x00FF00)
>>> Color.from_hsl((0.3333333333333333, 1.0, 0.5))
Color(0x00FF00)

rgba colors

>>> Color.from_rgba_int_float((0, 255, 0, 0.5))
Color(0x00FF00, alpha=0.5)

>>> Color.from_rgba_int_float((0, 255, 0, 0.5)).css_rgb
'rgba(0, 255, 0, 0.5)'
### convert RGBA color on RGB background to RGB color
>>> Color.from_background_and_color_alpha(
...     background=Color(0x00FF00),
...     color=Color(0x000000,alpha=0.5),
... )
Color(0x007F00)

make color darker or lighter

>>> green.darker(ratio=0.5) # lightness = lightness * ratio
Color(0x007F00)
>>> green.lighter(ratio=0.5) # lightness = lightness + (1 - lightness) * ratio
Color(0x7FFF7F)

determine the font color to be either black or white depending on the background color

>>> white = Color(0xFFFFFF)
>>> black = Color(0x000000)
>>> white.font_color()
Color(0x000000)
>>> black.font_color()
Color(0xFFFFFF)
>>> green.font_color()
Color(0x000000)

also return darker variation of color if it is really light (see same css-tricks article)

>>> green.font_border_colors()
(Color(0x000000), Color(0x00FF00))

Metadata

Release files for colortool 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for colortool 0.6.0
File Size Uploaded
colortool-0.6.0.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for colortool 0.6.0
File Interpreter ABI Platform
colortool-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.0 kB

Release files / colortool-0.6.0.tar.gz

Download URL colortool-0.6.0.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9250f69bb20bd6871c7a6fd43a6e4fbdefb0dbe8191b1baf540c71b11a99ba0b
BLAKE2b-256 checksum
How to use checksums
577d57998288ca302e7ab286ee2c1cbe4cef0d87d826d5f590f00f22c9fc1bf0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / colortool-0.6.0-py3-none-any.whl

Download URL colortool-0.6.0-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
75f765612cf65c1472a6dc8d940be1eb5f982f6789d8b8105c0dcabe73801cf2
BLAKE2b-256 checksum
How to use checksums
ad89440b1239ec27fea5891f1b24a15478902c838771040e445b06aa955e3f68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

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