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 also
Changed 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.
- property alpha¶
(
numbers.Real
) Alpha value, from 0.0 to 1.0.
- property alpha_int8¶
(
numbers.Integral
) Alpha value as 8bit integer which is a common style. From 0 to 255.New in version 0.3.0.
- property alpha_quantum¶
(
numbers.Integral
) Alpha value. Scale depends onQUANTUM_DEPTH
.New in version 0.3.0.
- property black¶
(
numbers.Real
) Black, or'K'
, color channel in CMYK colorspace. Unused by RGB colorspace.New in version 0.5.1.
- property black_int8¶
(
numbers.Integral
) Black value as 8bit integer which is a common style. From 0 to 255.New in version 0.5.1.
- property black_quantum¶
(
numbers.Integral
) Black. Scale depends onQUANTUM_DEPTH
.New in version 0.5.1.
- property blue¶
(
numbers.Real
) Blue, from 0.0 to 1.0.
- property blue_int8¶
(
numbers.Integral
) Blue as 8bit integer which is a common style. From 0 to 255.New in version 0.3.0.
- property 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 compareb (
ctypes.c_void_p
) – a pointer to PixelWand to compare
- Returns
True
only if two pixels equal- Return type
Note
It’s only for internal use. Don’t use it directly. Use
==
operator ofColor
instead.
- property cyan¶
(
numbers.Real
) Cyan color channel in CMYK colorspace. Unused by RGB colorspace.New in version 0.5.1.
- property cyan_int8¶
(
numbers.Integral
) Cyan value as 8bit integer which is a common style. From 0 to 255.New in version 0.5.1.
- property 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.
- property green¶
(
numbers.Real
) Green, from 0.0 to 1.0.
- property green_int8¶
(
numbers.Integral
) Green as 8bit integer which is a common style. From 0 to 255.New in version 0.3.0.
- property 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.
- property magenta¶
(
numbers.Real
) Magenta color channel in CMYK colorspace. Unused by RGB colorspace.New in version 0.5.1.
- property magenta_int8¶
(
numbers.Integral
) Magenta value as 8bit integer which is a common style. From 0 to 255.New in version 0.5.1.
- property 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.
- property red¶
(
numbers.Real
) Red, from 0.0 to 1.0.
- property red_int8¶
(
numbers.Integral
) Red as 8bit integer which is a common style. From 0 to 255.New in version 0.3.0.
- property red_quantum¶
(
numbers.Integral
) Red. Scale depends onQUANTUM_DEPTH
.New in version 0.3.0.
- property string¶
(
basestring
) The string representation of the color.
- property yellow¶
(
numbers.Real
) Yellow color channel in CMYK colorspace. Unused by RGB colorspace.New in version 0.5.1.
- property yellow_int8¶
(
numbers.Integral
) Yellow as 8bit integer which is a common style. From 0 to 255.New in version 0.5.1.
- property 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.Deprecated since version 0.6.6.
- Parameters
quantum (
numbers.Integral
) – quantum value- Returns
8bit integer of the given
quantum
value- Return type
New in version 0.3.0.
Changed in version 0.5.0: Added HDRI support