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
Hashes for materialyoucolor-2.0.8-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd8e614c60f6e3304cd724162065e4a75965376484d79ecdefe10d22f1d26ba1 |
|
MD5 | d3572e2bd61e3808ce58746db93f1f89 |
|
BLAKE2b-256 | 2989c0416717f180c6ed8040c7c84516b37a1cb6574d8b044cbb847d7eb8696c |
Hashes for materialyoucolor-2.0.8-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19c90894635489347a51b34254431b0c2df7a169262e147292e6a21e2e481423 |
|
MD5 | cc6d37a7afee08c35e03e1ec789075f5 |
|
BLAKE2b-256 | d75c1dd62639da51881a062e089713c6c8c02e6139f1445f1240ee40d51d3775 |
Hashes for materialyoucolor-2.0.8-cp312-cp312-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f233ba3dcadb5577bb3885f468fee4a7b990ce9ea671a07b26d2d9a622a90e8d |
|
MD5 | c67535e477af4fe60d009c5646a2eb26 |
|
BLAKE2b-256 | a090f7f5e80a9aa3007e103129623d2311025d0a022fea994d1527b2454825b5 |
Hashes for materialyoucolor-2.0.8-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e8a984e9ee381ee4e382b7fae5481263a5e66ea159eb605b2f542998d5e7e93 |
|
MD5 | 1651cc54a112b3aac3e6a2d123195230 |
|
BLAKE2b-256 | 6c0607402ffb8751021c0bf8486e3c0ee861a48058b9f8110a88f8b91f05a043 |
Hashes for materialyoucolor-2.0.8-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b8ef3a81430267cfc59b272555d37adeb78f43c2a3163505e205d101cfbdef3 |
|
MD5 | 3dd158b405e41cbd28873283de825ce9 |
|
BLAKE2b-256 | a10f00156f255b31ba2e5ff17bbab5066620c1d9d4f8894a25ae423221ff7ca0 |
Hashes for materialyoucolor-2.0.8-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9421e3f053fc934659852befd4c56a0e39c33b55cd6264cbb10d96440f81af94 |
|
MD5 | 44c9f40adcdeeb096d67b5052087db46 |
|
BLAKE2b-256 | 924e4cd8b2757135f1f31ef985b26b5cc15695d9dd5ef61c9146c712d988de8e |
Hashes for materialyoucolor-2.0.8-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80a8a5c776db0b752ec9a6a8b84b1150346b01f325c53565071a1e27982dd39f |
|
MD5 | de4888db7afc28880a5adf56619d56c9 |
|
BLAKE2b-256 | 56b6aa38a572fc676928e634496ed457d0c71034236046cebb531ef34a1012e1 |
Hashes for materialyoucolor-2.0.8-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96f7ab110461beacd93d24daecef3b656c2ba82f1270f781a47db0b9315e84bb |
|
MD5 | d17a6b28040a2405ad4f7906c902f115 |
|
BLAKE2b-256 | 32ee50173a5a88224a31ba587c3ef6b5e29e9986d8f1937ecf069f63bfbf5f0d |
Hashes for materialyoucolor-2.0.8-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 645567ada6a0bf65bc35b3c5919c94a91d89103c9bc7a5201f46616255a93825 |
|
MD5 | e4abb49273d8c06c15dfbd8457dccd76 |
|
BLAKE2b-256 | 85803ae0c404819cb21be23eea6c50cab3a47790a5394f87778efca2053b3d52 |
Hashes for materialyoucolor-2.0.8-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf83cae6b1b471732ffbaceb4f0a48c4f126c5f93305e89739be1baeda13a022 |
|
MD5 | e1f147661ae99da0a5dd78dd8e4931ab |
|
BLAKE2b-256 | 36056d959ba17135542eef62a2c1077f67e60959e6660538dcc205fee762a70a |
Hashes for materialyoucolor-2.0.8-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d00b03756f3ade45dc2cc8d59f8e48578f8783d8c4cf2a41dd1abf2346aeb341 |
|
MD5 | 7fc4f1b99ac0dfba56d4d7beaef668a4 |
|
BLAKE2b-256 | 9d7b9309c347676611dbd0eeaead5b982535ce608b7ca819abbd09a6a3691158 |
Hashes for materialyoucolor-2.0.8-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bccf054d67186fe99b718d3d4221283f285acb3d5807fc6e0ed95fcf435429c3 |
|
MD5 | 33be21a1ccb6093bac621586d671644a |
|
BLAKE2b-256 | e5db26b5c1e9868dd793d2c0cdcb4973cb963e2cc9e7ee107d098ad1d4ad8fc0 |
Hashes for materialyoucolor-2.0.8-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8920c1315b86c58df5c1a0aa7297a8d7db147af55e715695db15f8e1268d6c1e |
|
MD5 | ec6a33c4ef0e6bc66fa65ef0e17d7faf |
|
BLAKE2b-256 | efd9dd3f3d6529a17eddff2d5a1891e2651433f6bc79e7e52c44b61886f5a03e |