#NEWLINE# def PILExporter( image , file_handle , extension = '' , **kwargs ) : #NEWLINE# #INDENT# '\n    Given a file handle to write in to (which should act like a Python `file`\n    object), write out the image data. No value is returned.\n\n    Uses PIL to save the image and so supports most commonly used image\n    formats.\n\n    Parameters\n    ----------\n    image : map:`Image` or subclass\n        The image data to write out.\n    file_handle : `file`-like object\n        The file to write in to\n    ' #NEWLINE# from PIL.Image import EXTENSION #NEWLINE# if ( not EXTENSION ) : #NEWLINE# #INDENT# from PIL.Image import init , preinit #NEWLINE# preinit ( ) #NEWLINE# init ( ) #NEWLINE# #UNINDENT# pil_image = image . as_PILImage ( ) #NEWLINE# try : #NEWLINE# #INDENT# pil_extension = EXTENSION [ extension ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# raise ValueError ( 'PIL/Pillow does not support the provided extension: ({})' . format ( image ) ) #NEWLINE# #UNINDENT# pil_image . save ( file_handle , format = pil_extension )