Use python wand to grayscale image

grayscale, imagemagick, magickwand, python, wand

Solution

This can be achieved by setting the colorspace of the image.

from wand.image import Image
with Image(filename='color.jpg') as img:
    img.type = 'grayscale';
    img.save(filename='grayscale.jpg');

further reading:

- http://docs.wand-py.org/en/latest/wand/image.html#wand.image.IMAGE_TYPES

- http://docs.wand-py.org/en/latest/guide/colorspace.html

Problem

I want to use the Python API binding for ImageMagick http://wand-py.org to directly manipulate images. I am however not able to deduce from the documentation how to use a grayscale transformation. Can anybody provide information on this problem? ``` from wand.image import Image try: with Image(file=path) as img: img.grayscale() # PSEUDOCODE for my given problem except: pass ```

Original source