Skip to main content

Material You color generation algorithms in pure python!

Project description

image

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

  1. Up to date with material-foundation/material-color-utilities/.
  2. 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.

Click to view result

Image Used, size was 8MB

image image

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/develop.zip

Usage examples

  • 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

  1. How it is different from avanisubbiah/material-color-utilities?

See https://github.com/T-Dynamos/materialyoucolor-python/issues/3

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

materialyoucolor-2.0.6.tar.gz (49.2 kB view details)

Uploaded Source

Built Distributions

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

materialyoucolor-2.0.6-cp312-cp312-win_amd64.whl (110.4 kB view details)

Uploaded CPython 3.12Windows x86-64

materialyoucolor-2.0.6-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (132.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

materialyoucolor-2.0.6-cp312-cp312-macosx_10_9_universal2.whl (188.2 kB view details)

Uploaded CPython 3.12macOS 10.9+ universal2 (ARM64, x86-64)

materialyoucolor-2.0.6-cp311-cp311-win_amd64.whl (110.0 kB view details)

Uploaded CPython 3.11Windows x86-64

materialyoucolor-2.0.6-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (132.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

materialyoucolor-2.0.6-cp311-cp311-macosx_10_9_universal2.whl (193.3 kB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)

materialyoucolor-2.0.6-cp310-cp310-win_amd64.whl (108.9 kB view details)

Uploaded CPython 3.10Windows x86-64

materialyoucolor-2.0.6-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (130.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

materialyoucolor-2.0.6-cp310-cp310-macosx_11_0_x86_64.whl (119.3 kB view details)

Uploaded CPython 3.10macOS 11.0+ x86-64

materialyoucolor-2.0.6-cp39-cp39-win_amd64.whl (108.8 kB view details)

Uploaded CPython 3.9Windows x86-64

materialyoucolor-2.0.6-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (131.0 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

materialyoucolor-2.0.6-cp39-cp39-macosx_11_0_x86_64.whl (119.4 kB view details)

Uploaded CPython 3.9macOS 11.0+ x86-64

File details

Details for the file materialyoucolor-2.0.6.tar.gz.

File metadata

  • Download URL: materialyoucolor-2.0.6.tar.gz
  • Upload date:
  • Size: 49.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for materialyoucolor-2.0.6.tar.gz
Algorithm Hash digest
SHA256 c50d9f8b0ea1a91e56ef09849a2fd933fea46864792b076e4cb9872e7bc5c6f1
MD5 ad1de5c53f614cd099c89771b8fcab54
BLAKE2b-256 eb02b6a895d05fd29ef3a5f79aa9c757319c180096fdfa07cd12d123e050680e

See more details on using hashes here.

File details

Details for the file materialyoucolor-2.0.6-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for materialyoucolor-2.0.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ec444e472c1c7fdf1f05139e77349f60c1225bfc482202db5037e94e13e4ba3b
MD5 049530e4559c7c8859f8b29f4fe1b9cc
BLAKE2b-256 3244e5eb461ad74992d2a3ed2fccb1e1ae0062182b95d17ec83cbd8d0f0a14e4

See more details on using hashes here.

File details

Details for the file materialyoucolor-2.0.6-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for materialyoucolor-2.0.6-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 663d95674a1539e62a1d431c62fd81e8cff8f91d31019b581ee30b1825981975
MD5 38327e760842d69abdd3413cc679a201
BLAKE2b-256 4f00f2268b94a642cabecc8d36afa6308fa3246d10088dee6231b7da83a6ae52

See more details on using hashes here.

File details

Details for the file materialyoucolor-2.0.6-cp312-cp312-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for materialyoucolor-2.0.6-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 5b523e27160c0d49a9375c3c89e79d3fdcecf9d5848912df0f0edbf6fed2bc2e
MD5 c8f6caf151396d65ba4db4561e3ddc5e
BLAKE2b-256 73378bdb3d51bcd34a2e4bae4dba05b787306bb8ab438a0868147aa71eec1f01

See more details on using hashes here.

File details

Details for the file materialyoucolor-2.0.6-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for materialyoucolor-2.0.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 708ead02a183db70315e99b5a4678331577cdb8e4c1009f508f44ba7db997098
MD5 233fd91abdbb0adc4608d8784dacf2e0
BLAKE2b-256 622111a4822f3c7376ca5d0868d20fc414d2664c799617ee77cdd138135f9c6e

See more details on using hashes here.

File details

Details for the file materialyoucolor-2.0.6-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for materialyoucolor-2.0.6-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e79a010a6cd90a3acce711b4ad1a4160306c6487bc4fd3df83250479ca06b221
MD5 2f3689e4b778f7f73d38a46ee71d84e3
BLAKE2b-256 313f7783dec217d2f09b98fe61cf14c1c22f7c85e449fcd13ea15a3187bda300

See more details on using hashes here.

File details

Details for the file materialyoucolor-2.0.6-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for materialyoucolor-2.0.6-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 8196ac66f7765348e12de3cc0c5f8a9a6d659abf66e5decc4fddf6ce6bfbee12
MD5 7e8fb9f689b73108ac385c1e2563db79
BLAKE2b-256 73485bfb48d09da710edd44d13138ee5c84d03e85f921a0e1c20d5982e94fda8

See more details on using hashes here.

File details

Details for the file materialyoucolor-2.0.6-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for materialyoucolor-2.0.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d74113c521933aef03a18f7c1e5d4fe873ee01478307dd84d454fc8561412fd5
MD5 8ac3583f72f56f44d4fe45d86afe8f68
BLAKE2b-256 b95a23f1c036dc4f928ddca3d0bc89208075e1700c5717c6b4a3ff725eaea453

See more details on using hashes here.

File details

Details for the file materialyoucolor-2.0.6-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for materialyoucolor-2.0.6-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7e40cc70283698b3813a0db7e5f82a1c27d06e3d02cfd7a3e59c2a4626a5e4f9
MD5 272e808e34b17530cf6e9c79230ca7b3
BLAKE2b-256 780868ed0e0bc69fac3e399c0ac4ca23350a42364bf8337d71f0fd9142f56ba9

See more details on using hashes here.

File details

Details for the file materialyoucolor-2.0.6-cp310-cp310-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for materialyoucolor-2.0.6-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 20d8ce68cc3887fcc4eb9e76970fed92f6bdafa370efecedc59adabd20406ee4
MD5 1d12cd566a07b74a5838bef6cc1cfffb
BLAKE2b-256 80c58bd20754af47ce9cfb6635627caa6a1aac20575627297c124ddc8a30305e

See more details on using hashes here.

File details

Details for the file materialyoucolor-2.0.6-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for materialyoucolor-2.0.6-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 cb83bbe69c319b765daa3b2d58ad2b0f2bbc92fb520f1cee99fc531b23f92768
MD5 3269fe54c1830adf5a154ff515944843
BLAKE2b-256 8409f64971697e44210d0bab5c340c574382939ceee7bb08a87cb7b6b9c1ccd5

See more details on using hashes here.

File details

Details for the file materialyoucolor-2.0.6-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for materialyoucolor-2.0.6-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dcb172cb17f06e7f0f978b701b3eea2274bade45a99621c3efd64dd8e010f258
MD5 02df355807d68d9040fdf097abeaa1c3
BLAKE2b-256 823bc8fe46def2cf6902646a85f48ca37ea0727e72c4554156c15bcf70d48fde

See more details on using hashes here.

File details

Details for the file materialyoucolor-2.0.6-cp39-cp39-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for materialyoucolor-2.0.6-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 79bf61a14c8a842109fc20aa363df1eaf7ae18dbadb2ddb462fc5f7a9b1e06bf
MD5 3727d7655e998a37020ff7eed18c72f9
BLAKE2b-256 fbcbe7c102a53f9a1b2422fe7ce60238c6553357ca7fdde94c4ef86f12294737

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