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.7.tar.gz (49.4 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.7-cp312-cp312-win_amd64.whl (110.5 kB view details)

Uploaded CPython 3.12Windows x86-64

materialyoucolor-2.0.7-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (132.2 kB view details)

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

materialyoucolor-2.0.7-cp312-cp312-macosx_10_9_universal2.whl (188.3 kB view details)

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

materialyoucolor-2.0.7-cp311-cp311-win_amd64.whl (110.1 kB view details)

Uploaded CPython 3.11Windows x86-64

materialyoucolor-2.0.7-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (132.6 kB view details)

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

materialyoucolor-2.0.7-cp311-cp311-macosx_10_9_universal2.whl (193.4 kB view details)

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

materialyoucolor-2.0.7-cp310-cp310-win_amd64.whl (109.0 kB view details)

Uploaded CPython 3.10Windows x86-64

materialyoucolor-2.0.7-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (131.0 kB view details)

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

materialyoucolor-2.0.7-cp310-cp310-macosx_11_0_x86_64.whl (119.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ x86-64

materialyoucolor-2.0.7-cp39-cp39-win_amd64.whl (108.9 kB view details)

Uploaded CPython 3.9Windows x86-64

materialyoucolor-2.0.7-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (131.1 kB view details)

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

materialyoucolor-2.0.7-cp39-cp39-macosx_11_0_x86_64.whl (119.6 kB view details)

Uploaded CPython 3.9macOS 11.0+ x86-64

File details

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

File metadata

  • Download URL: materialyoucolor-2.0.7.tar.gz
  • Upload date:
  • Size: 49.4 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.7.tar.gz
Algorithm Hash digest
SHA256 b9ca69bf0e0b3e20ad619b989dae9857700bb312034b20c0c69f07ba2bb0068c
MD5 1bea6273e697ee281647a1935e600db3
BLAKE2b-256 bb1c97ba9812548b291fbf7a692afa5c5fc9e530cdc1c3911697afec64e0613c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for materialyoucolor-2.0.7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7e6cf01051f9d7770556042e0d0d86b9f4985e8bd5a236caaf03016d8849d26f
MD5 39a1efbb04c5372e825a20d69efc4422
BLAKE2b-256 f67e82565e59a5abc84984dab280107286a780221da5cc5b5cd031c8f9c4b8c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for materialyoucolor-2.0.7-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f0bcb910b9ac47fde9ccd9a8dc4c63b7535eb96af63170fc1a601d75de87bf99
MD5 160c37c5247cfc8ee66bb9c28c4f6f16
BLAKE2b-256 9576e44c35eb5c9ff514a72d4c757400657e0d345da83121315c447a9aa8f66b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for materialyoucolor-2.0.7-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 dbca9ab4158bcc375eb220c930ab9211fc43814ff67d172b7c2f73d6be57cfb2
MD5 b7459868a1032b775ac9ca1ec4234b11
BLAKE2b-256 812df3c452b42ed99da670f3db0d7a7313faf86a04af5c57d0edaa36beb77f49

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for materialyoucolor-2.0.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 5de99cebbe201ec9b4da32a4124f1ea686237bc7df466156da46cbd6c96476bd
MD5 8bf3b05c143b54bc630bb23afe328b01
BLAKE2b-256 3442e5e018a2c541122f5677fcd56630d968d7105b683dee1aa3d9d028787e2c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for materialyoucolor-2.0.7-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b535c7998b0cfe08e5c4852bfdf656ec89a52c7acc41ae8b914276597ca4bd03
MD5 0344e3c7e32b47a9f43c449cfff0fbad
BLAKE2b-256 b1975c846490ab6ec592ed2853a6d90dc3be4eb55c5e16bacb30670a3cf5b60d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for materialyoucolor-2.0.7-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 f6755be10e58b8a20ee12f4526f814470854fd138b42ef2eb782e15faab5208a
MD5 601ce3e153e74903a2057c1a0ff8f2d5
BLAKE2b-256 420bf8902e355f74d002c7fe5948115c5930f1be69ab87571b6c9f0a784ddb94

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for materialyoucolor-2.0.7-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d5bab0696e286fc49998dcb66cf55aeeca654b2f1606049166f1af4d0250c643
MD5 0b19af1157819b376d23c30fce2f65c7
BLAKE2b-256 b09af95a238c9d964e4ad051585906d0784b070aacbbf28a1042fd93b3e14199

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for materialyoucolor-2.0.7-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 09e270cec990510a976a1146d36369ac77f38dad1396bd8d742bd6d1bf6e6db8
MD5 e88fc00c3ef09a932a1107fca1f2ad85
BLAKE2b-256 1c9d142c924fcf7db5d73926e489af94ab7931662fb881a93e22e19049d3a3cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for materialyoucolor-2.0.7-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 c7234db3be526cefaa06878e28f556f50260ba6905a505217e1069ef757e7e71
MD5 c9a53fc15b108ddd5c759af0f1a8fc66
BLAKE2b-256 40720aa3d8770469840e6ebac83f941143c69c7f8b5b7c1c265238f510ae8159

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for materialyoucolor-2.0.7-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 4929f9cb5d8d951b981416669f0a86e49841f562452caa454870b53ee1a130e5
MD5 7081975343ecc9d1ba11a39624fa65e7
BLAKE2b-256 86e066f2d9210ecbf9ed2e2b9a49c9ae601bb7b6e768a9aeb95b859b91f37669

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for materialyoucolor-2.0.7-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9c41c257326b22ec9a5b7a98f2946c1d4e7c3494ca4f018834e31643399766a9
MD5 ce6c5cd49f5fc3c5b9747d4e78197e01
BLAKE2b-256 dc3bd56b5c8f9d1fe0589a7a28cf2db6ece414c501a8f34e2d4b4f52820b68fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for materialyoucolor-2.0.7-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 7dd9f6532f512ecad308e0ff8d09944358e6b52d41686aaa1555c28433172488
MD5 21620ff1a586cbd7bdd8387cd1845870
BLAKE2b-256 28cef9cee1f8e6ad6c951efdff8013ded0b57d4b5eee24cf82cc90592c7c535b

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