12345678910111213141516171819 |
- from io import BytesIO
- from PIL import Image, ImageDraw, ImageFont
- def byte2pil(byte_data):
- img = Image.open(BytesIO(byte_data))
- return img
- def pil2byte(img):
- img_bytes = BytesIO()
- img.save(img_bytes, format='JPEG')
- img_bytes = img_bytes.getvalue()
- return img_bytes
- def draw(img, text, position):
- font = ImageFont.truetype("font/SIMHEI.TTF", size=128)
- # print(font)
- draw = ImageDraw.Draw(img)
- draw.text(position, text, fill = (255, 0 ,0), font=font)
- return img
|