Package: materialyoucolor
Material You color algorithmsfor python!It is built in reference with officaltypescript implementationexcept it's color quantization part, which is based onc++ implementationthanks topybind.FeaturesUp to date withmaterial-foundation/material-color-utilities/.Uses official c++ sources for quantization backend, which makes color generation fast!Minimal running example:Run filetests/test_all.pyas:python3 test_all.py <image path> <quality>Maximum quality is1that means use all pixels, and quality number more than1means how many pixels to skip in between while reading, also you can see it as compression.Click to view resultImage Used, size was 8MBInstallYou can easily install it from pip by executing:pip3 install materialyoucolor --upgradePrebuilt binaries are avaliable forlinux,windowsandmacos. If prebuilt binaries aren't available, then you should manually build and install.Build and install#Installpip3 install https://github.com/T-Dynamos/materialyoucolor-python/archive/develop.zipUsage examplesGenerate non dynamic colorsfrommaterialyoucolor.schemeimportSchemefrommaterialyoucolor.scheme.scheme_androidimportSchemeAndroid# 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=0xff4181EEprint(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 androidprint(SchemeAndroid.light(color).props)print(SchemeAndroid.dark(color).props)Generate dynamic colors# Color in hue, chroma, tone formfrommaterialyoucolor.hctimportHctfrommaterialyoucolor.dynamiccolor.material_dynamic_colorsimportMaterialDynamicColors# There are 9 different variants of scheme.frommaterialyoucolor.scheme.scheme_tonal_spotimportSchemeTonalSpot# Others you can import: SchemeExpressive, SchemeFruitSalad, SchemeMonochrome, SchemeRainbow, SchemeVibrant, SchemeNeutral, SchemeFidelity and SchemeContent# SchemeTonalSpot is android defaultscheme=SchemeTonalSpot(# choose any scheme hereHct.from_int(0xff4181EE),# source color in hct formTrue,# dark mode0.0,# contrast)forcolorinvars(MaterialDynamicColors).keys():color_name=getattr(MaterialDynamicColors,color)ifhasattr(color_name,"get_hct"):# is a colorprint(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 pixelsfromPILimportImage# C++ QuantizeCelebifrommaterialyoucolor.quantizeimportQuantizeCelebi# Material You's default scoring of colorsfrommaterialyoucolor.score.scoreimportScore# Open imageimage=Image.open("path_to_some_image.jpg")pixel_len=image.width*image.heightimage_data=image.getdata()# Quality 1 means skip no pixelsquality=1pixel_array=[image_data[_]for_inrange(0,pixel_len,quality)]# Run algorithmresult=QuantizeCelebi(pixel_array,128)# 128 -> number desired colors, default 128print(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 populationprint(Score.score(result))# [4278722365, 4278723657]# list of selected colors in integer formFAQHow it is different fromavanisubbiah/material-color-utilities?Seehttps://github.com/T-Dynamos/materialyoucolor-python/issues/3