import io img = Image.open(img_path, mode='r') imgByteArr = io.BytesIO() img.save(imgByteArr, format='JPEG') imgByteArr = imgByteArr.getvalue()