mad-colorlib
v1.0.1
Published
Some utilities to deal with colors.
Downloads
1
Readme
Initialization: const colorlib = ColorLib()
colorlib.get_dominant(image, palette_size=1, use_limits=false)
This gets the dominant color or colors of an image. Palette size is the number of colors to return. If use_limits is true it will ignore colors when r, g, and b are below 10 or above 245.
colorlib.get_lighter_or_darker(rgb, amount=0.2)
This returns a darker color if the color is considered light, or a lighter color if the color is considered dark. rgb is an array like [0, 20, 5]. amount specifies how much darker or lighter it gets.
colorlib.is_light(rgb)
Checks if a color is considered light. Receives an rgb array.
colorlib.is_dark(rgb)
Checks if a color is considered dark. Receives an rgb array.
colorlib.get_proper_font(rgb)
Used to give a proper font color to a background color. If color is light it returns #000000. If color is dark it returns #ffffff. Although it's advised to use get_lighter_or_darker to achieve more natural contrasts.
colorlib.array_to_rgb(array)
Transforms an rgb array like [x, y, z] into rgb(x, y, z). An array with multiple array arguments can be passed.
colorlib.rgb_to_array(rgb)
Transforms rgb(x, y, z) to [x, y, z]. An array with multiple rgb arguments can be passed.
colorlib.rgb_to_rgba(rgb, alpha)
Replaces rgb(x, y, z) to rgba(x, y, z, alpha).
colorlib.rgba_to_rgb(rgb, alpha)
Replaces rgba(x, y, z, alpha) to rgb(x, y, z).
colorlib.rgb_to_hex(rgb, hash=true)
This turns an array to a hex string. If an rgb string is given it will convert it to an array automatically. For instance [1,2,3] or "rgb(1, 2, 3)" will turn to "#010203", If hash is false it won't add the # to the string.
colorlib.hex_to_rgb(hex)
This turns a hex string to an rgb array. For instance "#010203" or "010203" will return [1,2,3],
colorlib.check_array(array)
Checks if an rgb array is composed of valid values. A valid value is between 0 and 255. If a value is not in that range it is fixed. This returns a valid array, not true or false.
colorlib.check_rgb(rgb)
This checks if rgb is an array. If not, an array is created and returned. rgb(0, 1, 2) would return [0, 1, 2].