Skip to content

Instantly share code, notes, and snippets.

@kwist-sgr

kwist-sgr/png.py Secret

Created January 30, 2014 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwist-sgr/403bdf6ad1f9cdb1961d to your computer and use it in GitHub Desktop.
Save kwist-sgr/403bdf6ad1f9cdb1961d to your computer and use it in GitHub Desktop.
#!/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