def file_to_png ( fp ) : import PIL . Image # pylint: disable=import-error with io . BytesIO ( ) as dest : PIL . Image . open ( fp ) . save ( dest , "PNG" , optimize = True ) return dest . getvalue ( )
how to save an image back into file python
Convert an image to PNG format with Pillow . : arg file - like fp : The image file . : rtype : bytes
def file_to_png(fp):
	"""Convert an image to PNG format with Pillow.
	
	:arg file-like fp: The image file.
	:rtype: bytes
	"""
	import PIL.Image # pylint: disable=import-error
	with io.BytesIO() as dest:
		PIL.Image.open(fp).save(dest, "PNG", optimize=True)
		return dest.getvalue()