37 lines
627 B
Python
37 lines
627 B
Python
import io
|
|
|
|
from PIL import Image
|
|
|
|
# def _coder(im):
|
|
# if im:
|
|
# data = {
|
|
# 'pixels': im.tobytes(),
|
|
# 'size': im.size,
|
|
# 'mode': im.mode,
|
|
# }
|
|
# return data
|
|
#
|
|
#
|
|
# def _decoder(data):
|
|
# if data:
|
|
# im = Image.frombytes(data['mode'], data['size'], data['pixels'])
|
|
# return im
|
|
|
|
|
|
def _coder(im):
|
|
if im:
|
|
b = io.BytesIO()
|
|
im.save(b, format="png")
|
|
data = b.getvalue()
|
|
return data
|
|
|
|
|
|
def _decoder(data):
|
|
if data:
|
|
b = io.BytesIO(data)
|
|
im = Image.open(b)
|
|
return im
|
|
|
|
|
|
codec = (_coder, _decoder)
|