-
-
Save kwist-sgr/403bdf6ad1f9cdb1961d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from StringIO import StringIO | |
from io import BytesIO | |
from PIL import Image | |
if __name__ == '__main__': | |
with open('bad.png') as f: | |
bytes = ''.join(f.xreadlines()) | |
buffer = BytesIO(bytes) | |
image = Image.open(buffer) | |
if image.mode not in ('L', 'RGB', 'RGBA'): | |
image = image.convert('RGB') | |
out_file = StringIO() | |
image.save(out_file, "PNG") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment