{"id":284,"date":"2021-08-10T13:54:00","date_gmt":"2021-08-10T13:54:00","guid":{"rendered":"https:\/\/262235.xyz\/?p=284"},"modified":"2021-08-10T13:54:00","modified_gmt":"2021-08-10T13:54:00","slug":"284","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2021\/08\/10\/284\/","title":{"rendered":"Python\u811a\u672c\u5185\u5d4cbase64\u7f16\u7801\u70b9\u9635\u5b57\u4f53\uff0c\u65b9\u4fbf\u56fe\u7247\u586b\u5145\u6587\u5b57"},"content":{"rendered":"<h2>Python\u811a\u672c\u5185\u5d4cbase64\u7f16\u7801\u70b9\u9635\u5b57\u4f53\uff0c\u65b9\u4fbf\u56fe\u7247\u586b\u5145\u6587\u5b57<\/h2>\n<p>\u6211\u4eec\u77e5\u9053 <code>Pillow<\/code> \u56fe\u50cf\u5e93\u7684 <code>ImageFont<\/code> \u7c7b <code>PIL.ImageFont.load_default()<\/code> <a href=\"https:\/\/pillow.readthedocs.io\/en\/stable\/_modules\/PIL\/ImageFont.html#load_default\">\u6e90\u7801<\/a> \u662f\u4f7f\u7528 <code>base64<\/code> \u7f16\u7801\u628a\u4e00\u7ec4\u70b9\u9635\u5b57\u5e93\u5199\u5230\u5e93\u91cc\uff0c\u6211\u4eec\u53ef\u4ee5\u53c2\u8003\u4ed6\u7684\u6e90\u7801\uff0c\u628a\u81ea\u5df1\u7684\u70b9\u9635\u5b57\u5e93\u4f7f\u7528\u540c\u6837\u7684\u65b9\u6cd5\u5199\u5230\u811a\u672c\u6587\u4ef6\uff0c\u65b9\u4fbf\u7a0b\u5e8f\u8c03\u7528\u3002<\/p>\n<h2>\u7ecf\u8fc7\u8c03\u8bd5\u5b8c\u6210\u5185\u5d4cbase64\u7f16\u7801\u70b9\u9635\u5b57\u4f53\u5e93 <code>bitfont.py<\/code> <a href=\"https:\/\/github.com\/hongwenjun\/pillow_font\">\u5f00\u6e90\u4e0b\u8f7d<\/a><\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/08\/828349640.png\" alt=\"bitfont.png\" title=\"bitfont.png\"><\/p>\n<ul>\n<li>\n<p>\u4e0b\u8f7d  <code>bitfont.py<\/code> \u6587\u4ef6\uff0c\u8f93\u5165\u5982\u4e0b\u547d\u4ee4\uff0c\u5c31\u80fd\u663e\u793a\u6f14\u793a\u56fe<\/p>\n<pre><code>python3 bitfont.py<\/code><\/pre>\n<\/li>\n<\/ul>\n<h2>\u4f7f\u7528 <code>bitfont.py<\/code> \u5e93\u4ee3\u7801\u793a\u4f8b<\/h2>\n<ul>\n<li>\u5bfc\u5165\u5185\u5d4cbase64\u7f16\u7801\u70b9\u9635\u5b57\u4f53\u5e93 <code>import bitfont<\/code> \u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u6dfb\u52a0\u76842\u4e2a\u70b9\u9635\u5b57\u4f53 <code>Fixedsys<\/code> \u548c <code>VCRMono16<\/code>\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528 <code>bitfont.load_background()<\/code> \u52a0\u8f7d\u4e00\u5f20\u56fe\u7247\u5e95\u56fe<\/li>\n<\/ul>\n<pre><code>from PIL import Image, ImageDraw, ImageFont\nimport bitfont\n\nim = bitfont.load_background()\n(width, height) = (400, 310)\nim = im.resize((width, height))\ndraw = ImageDraw.Draw(im)\n\nfont_fds = bitfont.load_fixedsys()\ndraw.text((5, 10), \"FontName: Fixedsys\", (0, 0, 0),  font=font_fds)\n\nfont_vcr = bitfont.load_vcrmono()\ndraw.text((5, 40), \"FontName: VCRMono16.pil\", font=font_vcr)\n\ndraw.text((5, 90), bitfont.text[1], font=font_fds)\n\nfont = bitfont.load_default()\ndraw.text((5, 70), \"FontName: PIL_default\", (0, 255, 0),  font=font)\n\ndraw.text((5, 140), \"load_background: 50x50 Color Png image\", (255, 255, 0),  font=font_fds)\ndraw.text((5, 160), \"Fixedsys12.pil &amp; Fixedsys12.pbm Fixedsys font.\", (255, 255, 255),  font=font_fds)\ndraw.text((5, 200), \"VCRMono16.pil VCR_OSD_MONO font.\", (128, 255, 128),  font=font_vcr)\n\nim.save(\"bitfont_01.png\")\nim.show()<\/code><\/pre>\n<h3>\u5728\u6b64\u4e4b\u524d\u5df2\u7ecf\u5df2\u7ecf\u628aTTF\u8f6cBDF\u518d\u8f6cPIL\u5b57\u4f53\u7684\u5de5\u5177\u548c\u5b66\u4e60\u4ee3\u7801\u90fd\u653e\u5f00\u6e90\u9879\u76ee\u4e86<\/h3>\n<h3><a href=\"https:\/\/github.com\/hongwenjun\/pillow_font\">https:\/\/github.com\/hongwenjun\/pillow_font<\/a><\/h3>\n<h3>\u6709\u5174\u8da3\u5b66 Python \u56fe\u50cf\u5e93\u5b57\u4f53\u4f7f\u7528\uff0c\u53ef\u4ee5\u4e0b\u8f7d\u4f7f\u7528\u53c2\u8003<\/h3>\n","protected":false},"excerpt":{"rendered":"<p>Python\u811a\u672c\u5185\u5d4cbase64\u7f16\u7801\u70b9\u9635\u5b57\u4f53\uff0c\u65b9\u4fbf\u56fe\u7247\u586b\u5145\u6587\u5b57 \u6211\u4eec\u77e5\u9053 Pillow \u56fe\u50cf\u5e93\u7684 I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[45],"class_list":["post-284","post","type-post","status-publish","format-standard","hentry","category-learn","tag-python"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/284","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/comments?post=284"}],"version-history":[{"count":0,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/284\/revisions"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}