{"id":207504,"date":"2025-07-08T08:48:41","date_gmt":"2025-07-08T00:48:41","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207504\/"},"modified":"2025-07-08T08:48:41","modified_gmt":"2025-07-08T00:48:41","slug":"%e5%a6%82%e4%bd%95%e5%90%91%e4%bb%bb%e4%bd%95%e5%9b%be%e5%83%8f%e6%b7%bb%e5%8a%a0%e5%b8%a6%e6%9c%89%e9%bb%91%e8%89%b2%e9%98%b4%e5%bd%b1%e7%9a%84%e7%99%bd%e8%89%b2%e6%96%87%e6%9c%ac%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207504\/","title":{"rendered":"\u5982\u4f55\u5411\u4efb\u4f55\u56fe\u50cf\u6dfb\u52a0\u5e26\u6709\u9ed1\u8272\u9634\u5f71\u7684\u767d\u8272\u6587\u672c\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u5982\u4f55\u5411\u4efb\u4f55\u56fe\u50cf\u6dfb\u52a0\u5e26\u6709\u9ed1\u8272\u9634\u5f71\u7684\u767d\u8272\u6587\u672c\uff1f<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-23 09:54:35<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u6700\u8fd1\u53d1\u73b0\u4e0d\u5c11\u5c0f\u4f19\u4f34\u90fd\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u5f88\u611f\u5174\u8da3\uff0c\u6240\u4ee5\u4eca\u5929\u7ee7\u7eed\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\uff0c\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u5411\u4efb\u4f55\u56fe\u50cf\u6dfb\u52a0\u5e26\u6709\u9ed1\u8272\u9634\u5f71\u7684\u767d\u8272\u6587\u672c\uff1f\u300b<\/span>\u4e3b\u8981\u5185\u5bb9\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01\u5f53\u7136\u5982\u679c\u9605\u8bfb\u672c\u6587\u65f6\u5b58\u5728\u4e0d\u540c\u60f3\u6cd5\uff0c\u53ef\u4ee5\u5728\u8bc4\u8bba\u4e2d\u8868\u8fbe\uff0c\u4f46\u662f\u8bf7\u52ff\u4f7f\u7528\u8fc7\u6fc0\u7684\u63aa\u8f9e~<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u6b63\u5728\u4f7f\u7528 <code>github.com\/fogleman\/gg<\/code> \u5728\u56fe\u50cf\u4e0a\u7ed8\u5236\u4e00\u4e9b\u767d\u8272\u6587\u672c\uff1a<\/p>\n<pre>existing, _ := gg.LoadJPG(path)\ndc := gg.NewContextForImage(existing)\ndc.SetRGB(0, 0, 0)\ndc.DrawString(word, x, y)\ndc.SetRGB(1, 1, 1)\ndc.DrawString(word, x-3, y-3)<\/pre>\n<p>\u6709\u65f6\u5b83\u770b\u8d77\u6765\u5f88\u5b8c\u7f8e\uff1a<\/p>\n<p>\u4f46\u6709\u65f6\u8fd9\u5f88\u7cdf\u7cd5\uff1a<\/p>\n<p>\u6709\u4ec0\u4e48\u6280\u5de7\u53ef\u4ee5\u4f7f\u5176\u5728\u4efb\u4f55\u56fe\u50cf\u4e0a\u90fd\u53ef\u8bfb\u5417\uff1f<\/p>\n<p> <\/p>\n<h2>\u6b63\u786e\u7b54\u6848<\/h2>\n<p> <\/p>\n<p>\u54e6\uff0c\u6211\u60f3\u6211\u77e5\u9053\u8be5\u600e\u4e48\u505a\u4e86\uff1a<\/p>\n<\/p>\n<p>\u4f60\u5fc5\u987b\u4e3a\u6bcf\u4e2a\u5b57\u6bcd\u5236\u4f5c\u4e00\u4e2a\u5de8\u5927\u7684\u9ed1\u8272\u80cc\u666f\uff0c\u800c\u4e0d\u4ec5\u4ec5\u662f\u4e00\u4e2a\u5fae\u5c0f\u7684\u9634\u5f71\u3002<\/p>\n<pre>for i := 0; i &lt; 100; i++ {\n    angle := float64(i) \/ float64(smoothness) * 2 * math.pi\n    xoffset := math.cos(angle) * 4\n    yoffset := math.sin(angle) * 4\n    dc.drawstringanchored(letter, x+xoffset, y+yoffset, 0.5, 0.5)\n  }<\/pre>\n<p>\u66f4\u65b0\uff1a\u5728 python \u4e2d\u6267\u884c\u6b64\u64cd\u4f5c\u66f4\u5bb9\u6613\uff1a<\/p>\n<\/p>\n<pre>pip3 install pillow<\/pre>\n<pre>from PIL import Image, ImageDraw, ImageFont, ImageFilter, ImageChops\nimport sys\nimport random\n\nfilename = sys.argv[1]\nx = int(sys.argv[2])\ny = int(sys.argv[3])\ntext = sys.argv[4]\nresult = sys.argv[5]\n\nimage = Image.open(filename)\nbg = ImageDraw.Draw(image)\n\nfont = ImageFont.truetype('font.ttf',96)\n\ncolors = ['white', 'pink', 'green', 'orange', 'red', 'yellow', 'purple', 'cyan']\n\nfill_color = random.choice(colors)\n\nranX = random.randint(-10, 10)\nranY = random.randint(-10, 10)\n\nbg.text((x + ranX, y + ranY), text, fill=fill_color, font=font, spacing = 4, align = 'center', stroke_width=8, stroke_fill='black')\nimage.save(result)<\/pre>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300a\u5982\u4f55\u5411\u4efb\u4f55\u56fe\u50cf\u6dfb\u52a0\u5e26\u6709\u9ed1\u8272\u9634\u5f71\u7684\u767d\u8272\u6587\u672c\uff1f\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u516c\u4f17\u53f7\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-207504","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207504","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=207504"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207504\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}