2022년 4월 28일 목요일

Image to base64, base64 to image

PIL.UnidentifiedImageError: cannot identify image file


import base64

import io
from io import BytesIO
from PIL import Image

byteImgIO = io.BytesIO()
byteImg = Image.open('./images/img_small.png')
byteImg.save(byteImgIO, "PNG")
byteImgIO.seek(0)
byteImg = byteImgIO.read()
v2 = base64.b64encode(byteImg)
v3 = base64.b64decode(v2)
# i = Image.open(BytesIO(v3))
# i = i.convert('L')
i = BytesIO(v3)
i.seek(0)
i = Image.open(i)
i.save('./images/a.png')
print('finish')

댓글 없음:

댓글 쓰기

docker redmine 설치

docker-composer.yml version: '3.1' services:      redmine:           image: redmine           restart: always           container_na...