PIL corrupt png images with transparency if i make them grayscale. Why?
Here's my code:
input = Image.open('input.png')
output = ImageOps.grayscale(input)
output.save('output.png', **input.info)
Input
Output
is there a way to fix that?
You can use convert
method with luminance trick:
Image.open('input.png').convert('LA').save('output.png')
I ran into this issue as well. The only solution I've been able to find is to convert to 'LA' and then back to 'RGBA'
Try:
Image.open('input.png').convert('LA').convert('RGBA')
I was attempting to display the resulting grayscale PNG with transparency on a tkinter canvas, but I think this method will probably also work for saving the output.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With