看到 v2 上有一个 js 版小熊猫日记生成,我也用 Python 写了一个。 部署在 pythonanywhere 地址:[http://qwer110.pythonanywhere.com/][1] 可能有点慢,谅解一下,毕竟免费的。 *图片示例:
贴下核心代码
def create(): 139 if request.method == "GET": 140 text = request.args.get("text") 141 else: 142 text = request.form.get("text") 143 if text == "" or not text: 144 return jsonify(error="内容不能为空") 145 str_list = list() 146 for i in range(0, len(text), 24): 147 if i + 24 > len(text): 148 str_list.append(text[i:]) 149 else: 150 str_list.append(text[i:i + 24]) 151 txt = "\n".join(str_list) 152 img = Image.open('/home/QWER110/mysite/src/base.jpg') 153 fOnt= ImageFont.truetype('/home/QWER110/mysite/src/ios.ttf', 35) 154 draw = ImageDraw.Draw(img) 155 draw.text((31, 750), txt, (0, 0, 0), fOnt=font) 156 byte_io = BytesIO() 157 img.save(byte_io, 'JPEG') 158 byte_io.seek(0) 159 base64_img = "data:image/png;base64," + base64.b64encode(byte_io.getvalue()).decode('ascii') 160 return base64_img
![]() | 1 Marmot 2018-05-21 16:30:44 +08:00 可以的 666 |
2 teaser 2018-05-21 16:44:00 +08:00 真的骚 |
![]() | 3 CoCoMcRee 2018-05-21 17:11:30 +08:00 赞一个 |
![]() | 4 whx20202 2018-05-21 17:16:56 +08:00 能不能问一下怎么实现的呢?好奇怎么在图片中加入文字 还有一开始没文字的图片是怎么弄的 |
![]() | 6 mashirozx 2018-05-21 17:47:56 +08:00 via Android 敢问是只是单纯 pillow 拼了一下吗 |
7 mandy0119 2018-05-21 18:11:35 +08:00 字体有点小啊 |
![]() | 8 cheese 2018-05-21 18:19:04 +08:00 ![]() 高清的表情图没有灵魂 |
![]() | 9 littleshy 2018-05-21 19:09:58 +08:00 不居中一下吗? |
![]() | 10 E1n 2018-05-21 22:13:51 +08:00 这图片有点魔性啊 z |
![]() | 11 Artists 2018-05-21 22:38:25 +08:00 挺有趣的喔 |
12 fushall 2018-05-22 08:02:57 +08:00 2333333333 你太有才了 |
13 37miao 2018-05-22 10:14:30 +08:00 问下 js 版本的在哪呀,没搜到 |