def execute_job(self):
mode = self.get_argument("mode")
message = self.get_argument("msg")
thumb = self.get_argument("thumb")
# load setting
pos = config.images_dict[mode][2]
font_size = config.images_dict[mode][3]
font_color = config.images_dict[mode][4]
filename = config.image_path + config.images_dict[mode][5]
# gen picture
img = Image.open(filename)
draw = ImageDraw.Draw(img)
font = ImageFont.truetype(config.font_path, font_size)
imgW, imgH = img.size
textW, textH = draw.textsize(message,font=font)
# print(textW, textH)
draw.text(((imgW-textW)/2,pos),message,font_color,font=font)
# thumb
if thumb == "1":
img.thumbnail((300,300),Image.ANTIALIAS)
# gen file pointer
img_io = BytesIO()
img.save(img_io, 'JPEG', quality=100)
img_io.seek(0)
# return picture
return img_io.getvalue()
评论列表
文章目录