9

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
Mirzhan Irkegulov
  • 15,770
  • 8
  • 94
  • 154
user2075719
  • 101
  • 1
  • 5

2 Answers2

20

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:

Jen-Ya
  • 318
  • 4
  • 14
0

This is the correct code:

you need to transform the colorspace:

  with Image(filename=str(f)) as img:
        img.transform_colorspace('gray')