What’s new in Wand 0.6?

This guide doesn’t cover all changes in 0.6. See the full list of changes in 0.6 series.

CMYK & Gray Color Spaces Added to Numpy’s Array Interface

New in version 0.6.2.

When exporting pixel data into a Numpy array, Gray & CMYK color-spaces will be represented.

Note that the shape of the array only has one data channel for grayscale images.

>>> with Image(filename="rose:") as img:
...     img.transform_colorspace("gray")
...     print(np.array(img).shape)
(46, 70, 1)

As expected, CMYK images will export 4 bytes for each color channel.

>>> with Image(filename="rose:") as img:
...     img.transform_colorspace("cmyk")
...     print(np.array(img).shape)
(46, 70, 4)

Numpy array’s do not transport channel assignment by default, so users will be responsible for passing this information back into a raster library.

>>> with Image.form_array(my_cmyk_array, channel_map="cmyk")  as img:
...     img.save(filename="output.tiff")

Users expecting to keep RGBA array shapes should perform color space transformations before passing to Numpy.

>>> with Image(filename="cmyk_photo.tiff") as img:
...     if img.colorspace == "cmyk":
...         img.transform_colorspace("srgb")
...     arr = numpy.array(img)
...     arr = cv2.cvtColor(arr, cv2.COLOR_RGB2BGR)

Completed MagickWand API

The majority of the MagickWand API has been integrated into Wand between 0.5 & 0.6 release. Documentation referring to incomplete, or minimal integrations of the API have been updated.

Ensure to run Wand with the latest ImageMagick-7 library to take advantage of all the new methods.

Numpy I/O Fixes

The original integration of Numpy’s array interface exported shape data as ( WIDTH, HEIGHT, CHANNELS ). However many other imaging libraries that work with Numpy expect this shape data as ( ROWS, COLUMNS, CHANNELS ). Wand-0.6 adjusted the shape data to be in alignment & compatible with other libraries.

Documentation & Test Cases Ship with Source Distribution

The source distribution now includes Wand’s reStructuredText documentation, and pytest regression tests source files. Hopefully this will help offline users. See Running tests document for info on local testing.

Use setuptools-extra to install additional development dependencies:

pip install -U Wand[doc,test]

Improved Memory Deallocation & atexit Support

Several memory leaks have been addressed by reworking the wand.resource allocation & deallocation functions.

It’s still recommended to use Wand’s Image class in a with statement for proper memory-resource context:

with Image(filename='input.jpg') as img:
    pass

Users not using the with statement forfeit memory deallocation over to Python’s garbage-collector gc module.

The MagickWandTerminus() function is now only called during Python’s atexit shutdown routine.

Note

For “What’s New in Wand 0.5”, see previous announcements.