from colorspace import *
from colorspace.colorlib import hexcols
# Three colors without alpha
cols1 = ['#023FA5', '#E2E2E2', '#8E063B']
# Same colors with transparency 80%, 40%, 80%
cols2 = ['#023FA5CC', '#E2E2E266', '#8E063BCC']
# Convert hex color lists to colorobjects
x1 = hexcols(cols1)
x2 = hexcols(cols2)
# Extract transparency
extract_transparency(x1)Extract Alpha Channel
Description
Currently only for colorobjects. This function interfaces the .get() method of the object.
Usage
extract_transparency(x, mode='float')
Arguments
-
x -
an object which inherits from
colorsspace.colorlib.colorobjector an object of classcolorspace.palettes.palette. -
modestr -
mode of the return. One of
"float","int", or"str".
Return
None, numpy.ndarray: None if the colorobject has no alpha channel, else a numpy.ndarray. The dtype of the array depends on the mode specified.
Examples
extract_transparency(x2)array([0.8, 0.4, 0.8])
# Return mode
extract_transparency(x2, mode = "float")array([0.8, 0.4, 0.8])
extract_transparency(x2, mode = "int")array([204, 102, 204], dtype=int16)
extract_transparency(x2, mode = "str")array(['CC', '66', 'CC'], dtype='<U2')
# Extracting transparency from palette objects
from colorspace import palette
p1 = palette(cols1, name = "custom palette 1")
p2 = palette(cols2, name = "custom palette 2")# No return as colors in palette `p1` have no transparency
extract_transparency(p1, mode = "str")# Extracting transparency from colors in palette `p2`
extract_transparency(p2, mode = "str")array(['CC', '66', 'CC'], dtype='<U2')
Raises
-
TypeError: If input object does not inherit fromcolorobject. -
TypeError: If 'mode' is not str. -
ValueError: If 'mode' is not one of the allowed types shown in the arguments description.