Search code examples
pythonpngtransparencypython-imaging-library

Converting grayscale png with transparency using PIL


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

http://imgur.com/a/m50p6

Output

http://imgur.com/a/m50p6

is there a way to fix that?


Solution

  • You can use convert method with luminance trick:

    Image.open('input.png').convert('LA').save('output.png')