I am trying to grayscale with python using Wand, but when I do
from wand.image import Image
with Image(filename='image.png') as img:
img.type = 'grayscale'
img.save(filename='image_gray.png')
it turns the transparent background into black. If I use one with white background it works. What do I do wrong. And also as grayscaling is
Y = 0.2126 * RED + 0.7152 * GREEN + 0.0722 * BLUE
Where can I do that manually in Wand, say if I want to change the values a bit. I looked in the documentation and in various forums but I couldn’t find any answer, only stuff for photoshop.
Thanks!
2
Answers
this doesnt answer your question about wand … but you can do it easy enough with just pil …
or if you wanted to limit extremes based on a threshold
or if you wanted to filter a single color chanel
PNG image type set to grayscale removes transparent layer (see PNG docs). One option would be to enable the Alpha channel after setting grayscale.
Depending on which version you have, this might not work.
Another Option
Alter the color saturation with Image.modulate.
Another Option
Alter the colorspace.
Another Option
If your version has
Image.fx
. The following would work