File size: 384 Bytes
e7cae83
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
from typing import Any
import cv2
import numpy
import base64


def encode_array_to_base64(array : numpy.ndarray[Any, Any]) -> str:
	buffer = cv2.imencode('.jpg', array[:, :, ::-1])[1]
	return 'data:image/jpeg;base64,' + base64.b64encode(buffer.tobytes()).decode('utf-8')


def encode_pil_to_base64(image : Any) -> str:
	return encode_array_to_base64(numpy.asarray(image)[:, :, ::-1])