camstream/classes/image.py
2022-02-20 17:21:11 +01:00

32 lines
695 B
Python

from PIL.Image import open as PILopen
from io import BytesIO
import time
class Image:
@classmethod
def open(cls, *args, **kwargs):
img = PILopen(*args, **kwargs)
return cls(img)
def __init__(self, img):
self._img = img
def prepare_sending(self):
buffer = BytesIO()
self.save(buffer, "JPEG")
headers = {
'X-Timestamp': time.time(),
'Content-Length': len(buffer.getvalue()),
'Content-Type': "image/jpeg"
}
return buffer.getvalue(), headers
def __getattr__(self, key):
if key == '_img':
raise AttributeError()
return getattr(self._img, key)