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

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, ImageQuantizeCelebi
# 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

# Alternate C++ method
# this is generally faster, but gives less control over image
# result = ImageQuantizeCelebi("path_to_some_image.jpg", quality, 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.10.tar.gz (250.1 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.10-cp313-cp313-win_amd64.whl (151.8 kB view details)

Uploaded CPython 3.13Windows x86-64

materialyoucolor-2.0.10-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (208.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

materialyoucolor-2.0.10-cp313-cp313-macosx_10_13_universal2.whl (318.9 kB view details)

Uploaded CPython 3.13macOS 10.13+ universal2 (ARM64, x86-64)

materialyoucolor-2.0.10-cp312-cp312-win_amd64.whl (151.7 kB view details)

Uploaded CPython 3.12Windows x86-64

materialyoucolor-2.0.10-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (208.4 kB view details)

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

materialyoucolor-2.0.10-cp312-cp312-macosx_10_13_universal2.whl (318.8 kB view details)

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

materialyoucolor-2.0.10-cp311-cp311-win_amd64.whl (151.6 kB view details)

Uploaded CPython 3.11Windows x86-64

materialyoucolor-2.0.10-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (208.3 kB view details)

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

materialyoucolor-2.0.10-cp311-cp311-macosx_10_9_universal2.whl (319.4 kB view details)

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

materialyoucolor-2.0.10-cp310-cp310-win_amd64.whl (150.4 kB view details)

Uploaded CPython 3.10Windows x86-64

materialyoucolor-2.0.10-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (206.5 kB view details)

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

materialyoucolor-2.0.10-cp310-cp310-macosx_10_9_universal2.whl (316.1 kB view details)

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

materialyoucolor-2.0.10-cp39-cp39-win_amd64.whl (150.3 kB view details)

Uploaded CPython 3.9Windows x86-64

materialyoucolor-2.0.10-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (206.5 kB view details)

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

materialyoucolor-2.0.10-cp39-cp39-macosx_10_9_universal2.whl (316.3 kB view details)

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

File details

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

File metadata

  • Download URL: materialyoucolor-2.0.10.tar.gz
  • Upload date:
  • Size: 250.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for materialyoucolor-2.0.10.tar.gz
Algorithm Hash digest
SHA256 31b4d407b9a4fd4b54b30559b0d0313f6d6da1f9d19b75546ed65da52671ea76
MD5 79c64f432a9893dbf2125ef7ef2059d7
BLAKE2b-256 83b38835bacf50ea32bf000f9118f60da4c8e5febe80ab5929be18ce99a4baea

See more details on using hashes here.

File details

Details for the file materialyoucolor-2.0.10-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for materialyoucolor-2.0.10-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 2ffc8963a2f10d8acb6776e60e97f0e7929d3392eb282cf2bc63b8e56cd930b3
MD5 c6bf15b4ccd247cf3a6e03180e1bc86d
BLAKE2b-256 2a0105075b959b228c5c99c80703b7c63532ac6ee49abdf8054077e70908d6e3

See more details on using hashes here.

File details

Details for the file materialyoucolor-2.0.10-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for materialyoucolor-2.0.10-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 978748eca7725d8b569cdecfd9f86a8e34bf946182f79a48b059c98a10f1a0de
MD5 189d65590b7cd3e87dea489eae4151ea
BLAKE2b-256 4d62807bea1db749dc45debc2afa51ea4b27f5a219fbe73f6458c2bae2a15427

See more details on using hashes here.

File details

Details for the file materialyoucolor-2.0.10-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for materialyoucolor-2.0.10-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 71de9c581c8227c3010c61108a00af9a007c96f99358fdb0628626d0ade817d9
MD5 f12e5575384ed21941cc7b6256152165
BLAKE2b-256 ef49c4517231ec21bdd91a301cb40fdf86c632a95b10d86bc3278bd5d619480c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for materialyoucolor-2.0.10-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 aedc8596fd7583fd9e23f3e6d4f7b9defd7d5ef6e7889967814b9900c1e3d5b3
MD5 bc84f8d62cafe429f429b7c1733bc66b
BLAKE2b-256 eff21119e97e741b33717e26c494b4aa3c5ca57d770df4fa42707b698bfb7588

See more details on using hashes here.

File details

Details for the file materialyoucolor-2.0.10-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for materialyoucolor-2.0.10-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7fe5bbc63124c3ea2f5560ea4a5250af72fce9ab55d29925e6bac7c7ec65329d
MD5 1f56820764df1e47c52dae5a6e8cbfb6
BLAKE2b-256 fa672f3e70d707f86be3c541327693db5105622aa6aa1079d48ff90876d2e650

See more details on using hashes here.

File details

Details for the file materialyoucolor-2.0.10-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for materialyoucolor-2.0.10-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 0fc0b43a684536270177b71bf509b247dab4ff816e49d1ac1b124fc1a32e082e
MD5 7822c8ad5fbe7500ddc76a200a9ef01a
BLAKE2b-256 69e8847974020cde0e09124d7fb51bf41aa92cc3a9cad83f83911e5d67c1d665

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for materialyoucolor-2.0.10-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f126196a051673707297e86b8d0fbd90805a552dc3ac79e1d90442cc3fc877cb
MD5 e96c55bb7b5eff715f85aed2e7be9544
BLAKE2b-256 8243926ae82c04e5a5d02523f66e48af8021c0fdd8e01463a51e934137f7a5a0

See more details on using hashes here.

File details

Details for the file materialyoucolor-2.0.10-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for materialyoucolor-2.0.10-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 144fdd9dca272fee60a1779ce35acf24830cd3bc33ff20982ecba4936cb5bf91
MD5 70607daef2e0e54543b445454a43cf1f
BLAKE2b-256 29b104424f2bd811fe7e803d8a21cc28e8b4f9dea8b07cbc948318d4b4de3dd8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for materialyoucolor-2.0.10-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 e9a4dd1e444a64ea54982be06314ce4611f3c38fdfae2c33cca7d106f6383288
MD5 04dd65eea8f6ef151f923febd56ae325
BLAKE2b-256 04eb78d067df3948bd6a347677c10d35d89b6092916f78e0b98c51d47fd080f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for materialyoucolor-2.0.10-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 997787ec4224f3e2d9c90e99d82db746f5581670564a22a0f182ad377e704761
MD5 3bfa0a87db6f7b649d7436e1cc3be884
BLAKE2b-256 5e9105303aa40da51a71c4e828781a0a34b5ba8c88a9a0f2eec245c1257fe82e

See more details on using hashes here.

File details

Details for the file materialyoucolor-2.0.10-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for materialyoucolor-2.0.10-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ad22b0fb6980e0995d5b8437cad3411f628e1ea88c223c94a20b59d5dbcbacb2
MD5 5e852fe820009ff5a2e6eb18bdb73ea2
BLAKE2b-256 ea964f3919588aa341f8152ad01de784924ac26059077b095069f2ca83525053

See more details on using hashes here.

File details

Details for the file materialyoucolor-2.0.10-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for materialyoucolor-2.0.10-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 4de08ee488369cf0e055ae17ac43c62684f618781939feaf0ad11bc32572a4b6
MD5 b1fdc5185b0c31894ef6f5ee42bd6946
BLAKE2b-256 385236cf8bbb3989f31328ca2a06819b17c021052bcd97a7e703eadace1f225f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for materialyoucolor-2.0.10-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 4c5141fdd973ab386ebd0242072a7faab28d19cc083ee0d14f5b70c31ad75d60
MD5 10b903b683f54e30642ea8c158cac523
BLAKE2b-256 6bb9d8946d2d9901ca7bd088ea8efcdc975c73f51766b234fc3a83b821988b2b

See more details on using hashes here.

File details

Details for the file materialyoucolor-2.0.10-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for materialyoucolor-2.0.10-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d8cebae884c6106584e1792b910d9588778353255a1a8156cb634e21f1b8670e
MD5 83a73f561b3a9eb7c8bf3c861b9a479f
BLAKE2b-256 3cbe039f46e565b77ce088902c19352c073e16c34a4a8743c95fcad1a537d81f

See more details on using hashes here.

File details

Details for the file materialyoucolor-2.0.10-cp39-cp39-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for materialyoucolor-2.0.10-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 e4827307b1c78897f97f7989237ef688a5c21663a63d327d7cec8e47f107e509
MD5 ae6be3838659b899c5a9364c8d28f5dc
BLAKE2b-256 015629e59a5bcc92f0dc0a1de728e711edfcd971a6ef269a97cf461642fc339d

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