Material You color generation algorithms in pure python!
Project description
Material You color algorithms for python!
It is built in reference with offical typescript implementation except it's color quantization part, which is based on c++ implementation thanks to pybind.
Features
- Up to date with
material-foundation/material-color-utilities
. - Uses official c++ sources for quantization backend, which makes color generation fast!
Minimal running example:
Run file tests/test_all.py
as:
python3 test_all.py <image path> <quality>
Maximum quality is 1
that means use all pixels, and quality number more than 1
means how many pixels to skip in between while reading, also you can see it as compression.
Usage
Install
You can easily install it from pip by executing:
pip3 install materialyoucolor --upgrade
Prebuilt binaries are avaliable for linux
, windows
and macos
. If prebuilt binaries aren't available, then you should manually build and install.
Build and install
# Install
pip3 install https://github.com/T-Dynamos/materialyoucolor-python/archive/master.zip
OS Specific
Arch Linux
yay -S python-materialyoucolor
Thanks :heart: to @midn8hustlr for this AUR package.
Android (using kivy's buildozer
)
Ensure these lines in buildozer.spec
:
requirements = materialyoucolor
p4a.branch = develop
IOS (using kivy's kivy-ios
)
Install latest version of kivy-ios and use as:
toolchain build materialyoucolor
Usage examples
Click to show
- Generate non dynamic colors
from materialyoucolor.scheme import Scheme
from materialyoucolor.scheme.scheme_android import SchemeAndroid
# Color is a an int, which is made as:
# 0xff + hex_code (without #)
# Eg: 0xff + #4181EE = 0xff4181EE
# To convert hex to this form, do `int("0xff" + "<hex code>", 16)`
color = 0xff4181EE
print(Scheme.light(color).props)
print(Scheme.dark(color).props)
# Props is a dict, key is color name and value is rgba format list
# {'primary': [0, 90, 195, 255], 'onPrimary': ....
# Same way for android
print(SchemeAndroid.light(color).props)
print(SchemeAndroid.dark(color).props)
- Generate dynamic colors
# Color in hue, chroma, tone form
from materialyoucolor.hct import Hct
from materialyoucolor.dynamiccolor.material_dynamic_colors import MaterialDynamicColors
# There are 9 different variants of scheme.
from materialyoucolor.scheme.scheme_tonal_spot import SchemeTonalSpot
# Others you can import: SchemeExpressive, SchemeFruitSalad, SchemeMonochrome, SchemeRainbow, SchemeVibrant, SchemeNeutral, SchemeFidelity and SchemeContent
# SchemeTonalSpot is android default
scheme = SchemeTonalSpot( # choose any scheme here
Hct.from_int(0xff4181EE), # source color in hct form
True, # dark mode
0.0, # contrast
)
for color in vars(MaterialDynamicColors).keys():
color_name = getattr(MaterialDynamicColors, color)
if hasattr(color_name, "get_hct"): # is a color
print(color, color_name.get_hct(scheme).to_rgba()) # print name of color and value in rgba format
# background [14, 20, 21, 255]
# onBackground [222, 227, 229, 255]
# surface [14, 20, 21, 255]
# surfaceDim [14, 20, 21, 255]
# ...
- Generate and score colors from image
# Pillow is required to open image to array of pixels
from PIL import Image
# C++ QuantizeCelebi
from materialyoucolor.quantize import QuantizeCelebi
# Material You's default scoring of colors
from materialyoucolor.score.score import Score
# Open image
image = Image.open("path_to_some_image.jpg")
pixel_len = image.width * image.height
image_data = image.getdata()
# Quality 1 means skip no pixels
quality = 1
pixel_array = [image_data[_] for _ in range(0, pixel_len, quality)]
# Run algorithm
result = QuantizeCelebi(pixel_array, 128) # 128 -> number desired colors, default 128
print(result)
# {4278722365: 2320, 4278723396: 2405, 4278723657: 2366,...
# result is a dict where key is
# color in integer form (which you can convert later), and value is population
print(Score.score(result))
# [4278722365, 4278723657]
# list of selected colors in integer form
FAQ
- How it is different from
avanisubbiah/material-color-utilities
?
See https://github.com/T-Dynamos/materialyoucolor-python/issues/3
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 Distributions
File details
Details for the file materialyoucolor-2.0.9.tar.gz
.
File metadata
- Download URL: materialyoucolor-2.0.9.tar.gz
- Upload date:
- Size: 249.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 277e7ffe1ded5a7db47f97a3e8e5dac3834a9f1ba783dabb9b413865ff4f530e |
|
MD5 | 52e9af4aa8dd67d98d17355076e829e3 |
|
BLAKE2b-256 | 8c28009fdf9d9e9a75a37d65a6f8e0addf5e5f27a928650aa73356c67d08d164 |
File details
Details for the file materialyoucolor-2.0.9-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: materialyoucolor-2.0.9-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 150.6 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60f83c1be6cad4d9498bd575c3c2e71cd91cbf779e4c4a8a9d16a4edba732933 |
|
MD5 | 39d6e90f3d44ea17397cbeefce03643c |
|
BLAKE2b-256 | 942bc3a04e633d45ba303203ccb1a50778d63f29d6fcd633e7bfc0a63e41c323 |
File details
Details for the file materialyoucolor-2.0.9-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: materialyoucolor-2.0.9-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 205.9 kB
- Tags: CPython 3.12, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28748b587979eb7303d36387fa318a9dc1c516035dc1ccf754ca8a040595d550 |
|
MD5 | 9e9758ee3f201195afe541d15f29bb0a |
|
BLAKE2b-256 | 2e94a6f9c8f0da5046a6d0146a05f9b4aee3d462cf21f09ffa3c3130b247da3f |
File details
Details for the file materialyoucolor-2.0.9-cp312-cp312-macosx_10_9_universal2.whl
.
File metadata
- Download URL: materialyoucolor-2.0.9-cp312-cp312-macosx_10_9_universal2.whl
- Upload date:
- Size: 336.0 kB
- Tags: CPython 3.12, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6996b59ff5484c8d805ea29a977c72c762a7653682ab2e09ab3bf2ddd27dd360 |
|
MD5 | b21a43a3924697e70104c711db122c1a |
|
BLAKE2b-256 | 53322b834312369af7d9723831c92e8cd79b9646a9ddafe5c1054c0b9e986f34 |
File details
Details for the file materialyoucolor-2.0.9-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: materialyoucolor-2.0.9-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 150.4 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5853a6319021012038ec2cc966d4b24e189a67d09a26e98a32e35f37551a5403 |
|
MD5 | 69e13895544bfe37e0d1a76497acb351 |
|
BLAKE2b-256 | 31710b2d19440aee6a4d8fc092be9db99f797a62a2476bc7e462ff573efa0de9 |
File details
Details for the file materialyoucolor-2.0.9-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: materialyoucolor-2.0.9-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 205.8 kB
- Tags: CPython 3.11, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 512b525f22aa80e6f08319d41d73aaa970ccae2a4724624427a4a87af9d0f3c1 |
|
MD5 | 3570b247599f4a69fde545e356429282 |
|
BLAKE2b-256 | 4648380480a05239d07cb6e2eb6980c098c75fe15c235fa26af233350a9f25fc |
File details
Details for the file materialyoucolor-2.0.9-cp311-cp311-macosx_10_9_universal2.whl
.
File metadata
- Download URL: materialyoucolor-2.0.9-cp311-cp311-macosx_10_9_universal2.whl
- Upload date:
- Size: 340.6 kB
- Tags: CPython 3.11, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c76a121cfc637bcf38fc37756c574098c037e807a4bda22e3591bba11d62cb92 |
|
MD5 | ab7271768ba9d11ec145f3f04dfc1c60 |
|
BLAKE2b-256 | 74f841f742f0229397310122cd9c989c6d7f9d3514c600cffacd83cf602eec79 |
File details
Details for the file materialyoucolor-2.0.9-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: materialyoucolor-2.0.9-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 149.3 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 318942703579a3c87f3bc0bc5ea28b2765174f8fd9bdf10caccf8c975f10ce54 |
|
MD5 | 0a3e6504de84e2ec020964277794ce36 |
|
BLAKE2b-256 | 529c129bc9d25dfac38495894bcdd55ad0d62e7d2637273c9d7f6638c5490fdb |
File details
Details for the file materialyoucolor-2.0.9-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: materialyoucolor-2.0.9-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 203.9 kB
- Tags: CPython 3.10, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fa2ebd13fa6ae70e8803e4ce45b09031585b8f6fd1ad05b96ff657bf19e17ed |
|
MD5 | 5998641624605e6193ffdb7403d5b864 |
|
BLAKE2b-256 | dab120581fb722c646c2dba2dbe8ea84e892dd626423cd1f0e76734ebf07f2b5 |
File details
Details for the file materialyoucolor-2.0.9-cp310-cp310-macosx_11_0_x86_64.whl
.
File metadata
- Download URL: materialyoucolor-2.0.9-cp310-cp310-macosx_11_0_x86_64.whl
- Upload date:
- Size: 198.9 kB
- Tags: CPython 3.10, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ff1a9556cc49e5a83db3b5033b74bc4b685019588b19189ca01f56ad21cc240 |
|
MD5 | 1db55d81e970dc6160a049355157cfd3 |
|
BLAKE2b-256 | be9c5c13863f3cf18ca2fabeb66e01139728f88c908b8477390cf8d99f876195 |
File details
Details for the file materialyoucolor-2.0.9-cp310-cp310-macosx_10_9_universal2.whl
.
File metadata
- Download URL: materialyoucolor-2.0.9-cp310-cp310-macosx_10_9_universal2.whl
- Upload date:
- Size: 316.8 kB
- Tags: CPython 3.10, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 787daf74b7abc0eb0d6ea3a639ec6490413f3eec8cbd461f57af1e849c7f7016 |
|
MD5 | 09fbf7ec40067cca23b8707de9800671 |
|
BLAKE2b-256 | 6866de565f492e5281ff0a5cefe6ba33994bf1a7b90da9a0562f621252b8dda4 |
File details
Details for the file materialyoucolor-2.0.9-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: materialyoucolor-2.0.9-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 149.1 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a63959b25ed5cde9dd1d1f3ac744f6a3c0bc5751fe6f6811c1c7963de7cffec |
|
MD5 | be002d0087058ed3fc7a3e07c377d423 |
|
BLAKE2b-256 | ae4a581361abbc41f9517ea49ad55cc1a089471fee9162088cc7728c4a06c1cc |
File details
Details for the file materialyoucolor-2.0.9-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: materialyoucolor-2.0.9-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 204.1 kB
- Tags: CPython 3.9, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18a948245f778c5f1ae376eda6bfdd9792e888c0891f333df2ec962554df8d80 |
|
MD5 | 2bf2abf8e2d70271ac31750f51c90f54 |
|
BLAKE2b-256 | 03883769f05904b502632e83fa77901610fd32cb8e2889766386b8fc9e5457ab |
File details
Details for the file materialyoucolor-2.0.9-cp39-cp39-macosx_11_0_x86_64.whl
.
File metadata
- Download URL: materialyoucolor-2.0.9-cp39-cp39-macosx_11_0_x86_64.whl
- Upload date:
- Size: 199.1 kB
- Tags: CPython 3.9, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eff595d6e9d4434944f3385c85e358c367b90a198e804ace56e40fc4456ba90d |
|
MD5 | 2a4deaebf9f57e3328bac3175fb5e4d7 |
|
BLAKE2b-256 | 69bba1033debc1f6fbf6cb9987e44b901dac714aa64509b13c9891b9f05e158c |