wand.color
— Colors¶
New in version 0.1.2.
-
class
wand.color.
Color
(string=None, raw=None)¶ Color value.
Unlike any other objects in Wand, its resource management can be implicit when it used outside of
with
block. In these case, its resource are allocated for every operation which requires a resource and destroyed immediately. Of course it is inefficient when the operations are much, so to avoid it, you should use color objects inside ofwith
block explicitly e.g.:red_count = 0 with Color('#f00') as red: with Image(filename='image.png') as img: for row in img: for col in row: if col == red: red_count += 1
Parameters: string ( basestring
) – a color name string e.g.'rgb(255, 255, 255)'
,'#fff'
,'white'
. see ImageMagick Color Names doc alsoChanged in version 0.3.0:
Color
objects become hashable.Changed in version 0.5.1: Color channel properties can now be set.
Changed in version 0.5.1: Method
Color.from_hsl()
can create a RGB color fromhue
,saturation
, &lightness
values.See also
- ImageMagick Color Names
- The color can then be given as a color name (there is a limited but large set of these; see below) or it can be given as a set of numbers (in decimal or hexadecimal), each corresponding to a channel in an RGB or RGBA color model. HSL, HSLA, HSB, HSBA, CMYK, or CMYKA color models may also be specified. These topics are briefly described in the sections below.
-
== (other)
Equality operator.
Param other: a color another one Type color: Color
Returns: True
only if two images equal.Rtype: bool
-
alpha
¶ (
numbers.Real
) Alpha value, from 0.0 to 1.0.
-
alpha_int8
¶ (
numbers.Integral
) Alpha value as 8bit integer which is a common style. From 0 to 255.New in version 0.3.0.
-
alpha_quantum
¶ (
numbers.Integral
) Alpha value. Scale depends onQUANTUM_DEPTH
.New in version 0.3.0.
-
black
¶ (
numbers.Real
) Black, or'K'
, color channel in CMYK colorspace. Unused by RGB colorspace.New in version 0.5.1.
-
black_int8
¶ (
numbers.Integral
) Black value as 8bit integer which is a common style. From 0 to 255.New in version 0.5.1.
-
black_quantum
¶ (
numbers.Integral
) Black. Scale depends onQUANTUM_DEPTH
.New in version 0.5.1.
-
blue
¶ (
numbers.Real
) Blue, from 0.0 to 1.0.
-
blue_int8
¶ (
numbers.Integral
) Blue as 8bit integer which is a common style. From 0 to 255.New in version 0.3.0.
-
blue_quantum
¶ (
numbers.Integral
) Blue. Scale depends onQUANTUM_DEPTH
.New in version 0.3.0.
-
static
c_equals
(a, b)¶ Raw level version of equality test function for two pixels.
Parameters: - a (
ctypes.c_void_p
) – a pointer to PixelWand to compare - b (
ctypes.c_void_p
) – a pointer to PixelWand to compare
Returns: True
only if two pixels equalReturn type: Note
It’s only for internal use. Don’t use it directly. Use
==
operator ofColor
instead.- a (
-
cyan
¶ (
numbers.Real
) Cyan color channel in CMYK colorspace. Unused by RGB colorspace.New in version 0.5.1.
-
cyan_int8
¶ (
numbers.Integral
) Cyan value as 8bit integer which is a common style. From 0 to 255.New in version 0.5.1.
-
cyan_quantum
¶ (
numbers.Integral
) Cyan. Scale depends onQUANTUM_DEPTH
.New in version 0.5.1.
-
classmethod
from_hsl
(hue=0.0, saturation=0.0, lightness=0.0)¶ Creates a RGB color from HSL values. The
hue
,saturation
, andlightness
must be normalized between 0.0 & 1.0.h=0.75 # 270 Degrees s=1.0 # 100 Percent l=0.5 # 50 Percent with Color.from_hsl(hue=h, saturation=s, lightness=l) as color: print(color) #=> srgb(128,0,255)
Parameters: - hue (
numbers.Real
) – a normalized double between 0.0 & 1.0. - saturation (
numbers.Real
) – a normalized double between 0.0 & 1.0. - lightness (
numbers.Real
) – a normalized double between 0.0 & 1.0.
Return type: New in version 0.5.1.
- hue (
-
green
¶ (
numbers.Real
) Green, from 0.0 to 1.0.
-
green_int8
¶ (
numbers.Integral
) Green as 8bit integer which is a common style. From 0 to 255.New in version 0.3.0.
-
green_quantum
¶ (
numbers.Integral
) Green. Scale depends onQUANTUM_DEPTH
.New in version 0.3.0.
-
hsl
()¶ Calculate the HSL color values from the RGB color.
Returns: Tuple containing three normalized doubles, between 0.0 & 1.0, representing hue
,saturation
, andlightness
.Return type: collections.Sequence
New in version 0.5.1.
-
magenta
¶ (
numbers.Real
) Magenta color channel in CMYK colorspace. Unused by RGB colorspace.New in version 0.5.1.
-
magenta_int8
¶ (
numbers.Integral
) Magenta value as 8bit integer which is a common style. From 0 to 255.New in version 0.5.1.
-
normalized_string
¶ (
basestring
) The normalized string representation of the color. The same color is always represented to the same string.New in version 0.3.0.
-
red
¶ (
numbers.Real
) Red, from 0.0 to 1.0.
-
red_int8
¶ (
numbers.Integral
) Red as 8bit integer which is a common style. From 0 to 255.New in version 0.3.0.
-
red_quantum
¶ (
numbers.Integral
) Red. Scale depends onQUANTUM_DEPTH
.New in version 0.3.0.
-
string
¶ (
basestring
) The string representation of the color.
-
yellow
¶ (
numbers.Real
) Yellow color channel in CMYK colorspace. Unused by RGB colorspace.New in version 0.5.1.
-
yellow_int8
¶ (
numbers.Integral
) Yellow as 8bit integer which is a common style. From 0 to 255.New in version 0.5.1.
-
yellow_quantum
¶ (
numbers.Integral
) Yellow. Scale depends onQUANTUM_DEPTH
.New in version 0.5.1.
-
wand.color.
scale_quantum_to_int8
(quantum)¶ Straightforward port of
ScaleQuantumToChar()
inline function.Parameters: quantum ( numbers.Integral
) – quantum valueReturns: 8bit integer of the given quantum
valueReturn type: numbers.Integral
New in version 0.3.0.
Changed in version 0.5.0: Added HDRI support