wand.color — Colors

New in version 0.1.2.

class wand.color.Color(string=None, raw=None)

Color value.

Unlike other objects in Wand, its resource management can be implicit when used outside of a with block. In these cases, its resource is allocated for every operation which requires a resource and destroyed immediately. Of course it is inefficient when many operations are applied, so to avoid it, you should use color objects inside of an explicit with block, 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 (str) – 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: Added cyan, magenta, yellow, & black properties for CMYK Color instances.

Changed in version 0.5.1: Method Color.from_hsl() can create a RGB color from hue, 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

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 on QUANTUM_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 on QUANTUM_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 on QUANTUM_DEPTH.

New in version 0.3.0.

c_clear_exception = wand.api.library.PixelClearException

(ctypes.CFUNCTYPE) The ctypes function that clears an exception of the resource.

Note

It is an abstract attribute that has to be implemented in the subclass.

c_destroy_resource = wand.api.library.DestroyPixelWand

(ctypes.CFUNCTYPE) The ctypes function that destroys the resource.

Note

It is an abstract attribute that has to be implemented in the subclass.

static c_equals(a, b)

Raw level version of equality test function for two pixels.

Parameters:
Returns:

True only if two pixels equal

Return type:

bool

Note

It’s only for internal use. Don’t use it directly. Use == operator of Color instead.

c_get_exception = wand.api.library.PixelGetException

(ctypes.CFUNCTYPE) The ctypes function that gets an exception from the resource.

Note

It is an abstract attribute that has to be implemented in the subclass.

c_is_resource = wand.api.library.IsPixelWand

(ctypes.CFUNCTYPE) The ctypes predicate function that returns whether the given pointer (that contains a resource data usually) is a valid resource.

Note

It is an abstract attribute that has to be implemented in the subclass.

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 on QUANTUM_DEPTH.

New in version 0.5.1.

dirty = None

(bool) Whether the color has changed or not.

classmethod from_hsl(hue=0.0, saturation=0.0, lightness=0.0)

Creates a RGB color from HSL values. The hue, saturation, and lightness 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:

Color

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 on QUANTUM_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, and lightness.

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

(str) 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 on QUANTUM_DEPTH.

New in version 0.3.0.

property string

(str) 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 on QUANTUM_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:

numbers.Integral

New in version 0.3.0.

Changed in version 0.5.0: Added HDRI support