from colorspace import *
from colorspace.colorlib import hexcols
# Three colors without alpha
= ['#023FA5', '#E2E2E2', '#8E063B']
cols1 # Same colors with transparency 80%, 40%, 80%
= ['#023FA5CC', '#E2E2E266', '#8E063BCC']
cols2
# Convert hex color lists to colorobjects
= hexcols(cols1)
x1 = hexcols(cols2)
x2 # 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.colorobject
or an object of classcolorspace.palettes.palette
. -
mode
str
-
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
= "float") extract_transparency(x2, mode
array([0.8, 0.4, 0.8])
= "int") extract_transparency(x2, mode
array([204, 102, 204], dtype=int16)
= "str") extract_transparency(x2, mode
array(['CC', '66', 'CC'], dtype='<U2')
# Extracting transparency from palette objects
from colorspace import palette
= palette(cols1, name = "custom palette 1")
p1 = palette(cols2, name = "custom palette 2") p2
# No return as colors in palette `p1` have no transparency
= "str") extract_transparency(p1, mode
# Extracting transparency from colors in palette `p2`
= "str") extract_transparency(p2, mode
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.