from pymaging.formats import Format
from pymaging_png.writer import write
from .reader import Reader, PNGReaderError

def open_image(fileobj):
    reader = Reader(fileobj=fileobj)
    try:
        return reader.get_image()
    except PNGReaderError:
        fileobj.seek(0)
        import traceback;traceback.print_exc()
        return None

PNG = Format(open_image, write, ['png'])
