{"id":1142916,"date":"2025-01-08T22:45:02","date_gmt":"2025-01-08T14:45:02","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1142916.html"},"modified":"2025-01-08T22:45:06","modified_gmt":"2025-01-08T14:45:06","slug":"python%e4%ba%8c%e7%bb%b4%e7%a0%81%e5%a6%82%e4%bd%95%e6%b7%bb%e5%8a%a0%e5%be%ae%e4%bf%a1%e5%85%ac%e4%bc%97%e5%8f%b7","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1142916.html","title":{"rendered":"python\u4e8c\u7ef4\u7801\u5982\u4f55\u6dfb\u52a0\u5fae\u4fe1\u516c\u4f17\u53f7"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24180759\/df100ad1-55d4-4daf-b3e2-2647dad90f7d.webp\" alt=\"python\u4e8c\u7ef4\u7801\u5982\u4f55\u6dfb\u52a0\u5fae\u4fe1\u516c\u4f17\u53f7\" \/><\/p>\n<p><p> <strong>Python\u4e8c\u7ef4\u7801\u5982\u4f55\u6dfb\u52a0\u5fae\u4fe1\u516c\u4f17\u53f7<\/strong><\/p>\n<\/p>\n<p><p><strong>Python\u751f\u6210\u4e8c\u7ef4\u7801\u5e76\u6dfb\u52a0\u5fae\u4fe1\u516c\u4f17\u53f7\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528qrcode\u5e93\u751f\u6210\u4e8c\u7ef4\u7801\u3001\u4f7f\u7528Pillow\u5e93\u6dfb\u52a0\u5fae\u4fe1\u516c\u4f17\u53f7\u4e8c\u7ef4\u7801\u3001\u5bf9\u4e8c\u7ef4\u7801\u8fdb\u884c\u7f8e\u5316\u3002<\/strong>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u5982\u4f55\u901a\u8fc7Python\u751f\u6210\u4e8c\u7ef4\u7801\u5e76\u6dfb\u52a0\u5fae\u4fe1\u516c\u4f17\u53f7\uff0c\u5177\u4f53\u64cd\u4f5c\u6b65\u9aa4\u3001\u4ee3\u7801\u793a\u4f8b\u4ee5\u53ca\u4f18\u5316\u4e8c\u7ef4\u7801\u7684\u7f8e\u89c2\u5ea6\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u4f7f\u7528qrcode\u5e93\u751f\u6210\u4e8c\u7ef4\u7801<\/h2>\n<\/p>\n<p><p>Python\u4e2d\u7684<code>qrcode<\/code>\u5e93\u662f\u4e00\u4e2a\u975e\u5e38\u7b80\u5355\u4e14\u5b9e\u7528\u7684\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u5de5\u5177\u3002\u901a\u8fc7\u5b83\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u751f\u6210\u5e26\u6709\u6211\u4eec\u6240\u9700\u4fe1\u606f\u7684\u4e8c\u7ef4\u7801\u3002<\/p>\n<\/p>\n<p><h3>1. \u5b89\u88c5qrcode\u5e93<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5<code>qrcode<\/code>\u5e93\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u901a\u8fc7pip\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install qrcode[pil]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2. \u751f\u6210\u4e8c\u7ef4\u7801<\/h3>\n<\/p>\n<p><p>\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u6b65\u9aa4\u975e\u5e38\u7b80\u5355\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u57fa\u672c\u7684\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import qrcode<\/p>\n<h2><strong>\u751f\u6210\u4e8c\u7ef4\u7801<\/strong><\/h2>\n<p>data = &quot;https:\/\/mp.weixin.qq.com\/&quot;<\/p>\n<p>qr = qrcode.QRCode(<\/p>\n<p>    version=1,<\/p>\n<p>    error_correction=qrcode.constants.ERROR_CORRECT_L,<\/p>\n<p>    box_size=10,<\/p>\n<p>    border=4,<\/p>\n<p>)<\/p>\n<p>qr.add_data(data)<\/p>\n<p>qr.make(fit=True)<\/p>\n<h2><strong>\u521b\u5efa\u56fe\u50cf<\/strong><\/h2>\n<p>img = qr.make_image(fill_color=&quot;black&quot;, back_color=&quot;white&quot;)<\/p>\n<p>img.save(&quot;qrcode.png&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3. \u53c2\u6570\u8bf4\u660e<\/h3>\n<\/p>\n<ul>\n<li><strong>version<\/strong>: \u63a7\u5236\u4e8c\u7ef4\u7801\u7684\u5927\u5c0f\uff0c\u53d6\u503c\u8303\u56f4\u662f1\u523040\uff0c\u6570\u5b57\u8d8a\u5927\uff0c\u4e8c\u7ef4\u7801\u8d8a\u5927\u3002<\/li>\n<li><strong>error_correction<\/strong>: \u63a7\u5236\u4e8c\u7ef4\u7801\u7684\u5bb9\u9519\u7387\u3002\u53ef\u9009\u503c\u6709\uff1a\n<ul>\n<li><strong>ERROR_CORRECT_L<\/strong>: \u5927\u7ea67%\u7684\u9519\u8bef\u80fd\u88ab\u7ea0\u6b63\u3002<\/li>\n<li><strong>ERROR_CORRECT_M<\/strong>: \uff08\u9ed8\u8ba4\uff09\u5927\u7ea615%\u7684\u9519\u8bef\u80fd\u88ab\u7ea0\u6b63\u3002<\/li>\n<li><strong>ERROR_CORRECT_Q<\/strong>: \u5927\u7ea625%\u7684\u9519\u8bef\u80fd\u88ab\u7ea0\u6b63\u3002<\/li>\n<li><strong>ERROR_CORRECT_H<\/strong>: \u5927\u7ea630%\u7684\u9519\u8bef\u80fd\u88ab\u7ea0\u6b63\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>box_size<\/strong>: \u63a7\u5236\u4e8c\u7ef4\u7801\u4e2d\u6bcf\u4e2a\u5c0f\u683c\u5b50\u7684\u50cf\u7d20\u6570\u3002<\/li>\n<li><strong>border<\/strong>: \u63a7\u5236\u4e8c\u7ef4\u7801\u7684\u8fb9\u6846\u5bbd\u5ea6\uff08\u9ed8\u8ba4\u4e3a4\uff09\u3002<\/li>\n<\/ul>\n<p><h2>\u4e8c\u3001\u4f7f\u7528Pillow\u5e93\u6dfb\u52a0\u5fae\u4fe1\u516c\u4f17\u53f7\u4e8c\u7ef4\u7801<\/h2>\n<\/p>\n<p><h3>1. \u5b89\u88c5Pillow\u5e93<\/h3>\n<\/p>\n<p><p>\u6211\u4eec\u8fd8\u9700\u8981\u4f7f\u7528Pillow\u5e93\u6765\u5904\u7406\u56fe\u50cf\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pillow<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2. \u5408\u6210\u4e8c\u7ef4\u7801\u548c\u5fae\u4fe1\u516c\u4f17\u53f7\u4e8c\u7ef4\u7801<\/h3>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5c06\u751f\u6210\u7684\u4e8c\u7ef4\u7801\u548c\u5fae\u4fe1\u516c\u4f17\u53f7\u4e8c\u7ef4\u7801\u5408\u6210\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<p>def add_logo_to_qrcode(qrcode_path, logo_path, output_path):<\/p>\n<p>    # \u6253\u5f00\u4e8c\u7ef4\u7801\u56fe\u50cf<\/p>\n<p>    qr_img = Image.open(qrcode_path)<\/p>\n<p>    # \u6253\u5f00logo\u56fe\u50cf<\/p>\n<p>    logo_img = Image.open(logo_path)<\/p>\n<p>    # \u8ba1\u7b97logo\u7684\u5927\u5c0f<\/p>\n<p>    qr_width, qr_height = qr_img.size<\/p>\n<p>    logo_size = qr_width \/\/ 4<\/p>\n<p>    logo_img = logo_img.resize((logo_size, logo_size))<\/p>\n<p>    # \u8ba1\u7b97logo\u7684\u4f4d\u7f6e<\/p>\n<p>    x = (qr_width - logo_size) \/\/ 2<\/p>\n<p>    y = (qr_height - logo_size) \/\/ 2<\/p>\n<p>    # \u5c06logo\u6dfb\u52a0\u5230\u4e8c\u7ef4\u7801\u4e0a<\/p>\n<p>    qr_img.paste(logo_img, (x, y), logo_img)<\/p>\n<p>    # \u4fdd\u5b58\u6700\u7ec8\u7684\u56fe\u50cf<\/p>\n<p>    qr_img.save(output_path)<\/p>\n<h2><strong>\u4f7f\u7528\u8be5\u51fd\u6570\u5c06logo\u6dfb\u52a0\u5230\u4e8c\u7ef4\u7801\u4e2d<\/strong><\/h2>\n<p>add_logo_to_qrcode(&quot;qrcode.png&quot;, &quot;wechat_logo.png&quot;, &quot;qrcode_with_logo.png&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06\u751f\u6210\u7684\u4e8c\u7ef4\u7801\u548c\u5fae\u4fe1\u516c\u4f17\u53f7\u7684\u4e8c\u7ef4\u7801\uff08logo\uff09\u5408\u6210\u4e3a\u4e00\u5f20\u65b0\u7684\u56fe\u50cf\u3002<strong>\u6838\u5fc3\u6b65\u9aa4\u662f\uff1a\u6253\u5f00\u4e8c\u7ef4\u7801\u548clogo\u56fe\u50cf\u3001\u8c03\u6574logo\u5927\u5c0f\u3001\u8ba1\u7b97\u4f4d\u7f6e\u3001\u5c06logo\u7c98\u8d34\u5230\u4e8c\u7ef4\u7801\u4e0a<\/strong>\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u5bf9\u4e8c\u7ef4\u7801\u8fdb\u884c\u7f8e\u5316<\/h2>\n<\/p>\n<p><p>\u4e3a\u4e86\u4f7f\u4e8c\u7ef4\u7801\u66f4\u52a0\u7f8e\u89c2\uff0c\u6211\u4eec\u53ef\u4ee5\u8fdb\u884c\u4e00\u4e9b\u7f8e\u5316\u5904\u7406\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u7f8e\u5316\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><h3>1. \u8c03\u6574\u4e8c\u7ef4\u7801\u989c\u8272<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u8c03\u6574\u4e8c\u7ef4\u7801\u548c\u80cc\u666f\u7684\u989c\u8272\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u4e8c\u7ef4\u7801\u66f4\u52a0\u7f8e\u89c2\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">img = qr.make_image(fill_color=&quot;blue&quot;, back_color=&quot;white&quot;)<\/p>\n<p>img.save(&quot;color_qrcode.png&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2. \u6dfb\u52a0\u80cc\u666f\u56fe\u50cf<\/h3>\n<\/p>\n<p><p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u5c06\u4e8c\u7ef4\u7801\u53e0\u52a0\u5728\u80cc\u666f\u56fe\u50cf\u4e0a\uff0c\u4f7f\u5176\u66f4\u52a0\u7f8e\u89c2\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def add_background_to_qrcode(qrcode_path, background_path, output_path):<\/p>\n<p>    # \u6253\u5f00\u4e8c\u7ef4\u7801\u56fe\u50cf<\/p>\n<p>    qr_img = Image.open(qrcode_path)<\/p>\n<p>    # \u6253\u5f00\u80cc\u666f\u56fe\u50cf<\/p>\n<p>    bg_img = Image.open(background_path)<\/p>\n<p>    # \u8c03\u6574\u80cc\u666f\u56fe\u50cf\u5927\u5c0f\u4e3a\u4e8c\u7ef4\u7801\u56fe\u50cf\u5927\u5c0f<\/p>\n<p>    bg_img = bg_img.resize(qr_img.size)<\/p>\n<p>    # \u5c06\u4e8c\u7ef4\u7801\u6dfb\u52a0\u5230\u80cc\u666f\u56fe\u50cf\u4e0a<\/p>\n<p>    bg_img.paste(qr_img, (0, 0), qr_img)<\/p>\n<p>    # \u4fdd\u5b58\u6700\u7ec8\u7684\u56fe\u50cf<\/p>\n<p>    bg_img.save(output_path)<\/p>\n<h2><strong>\u4f7f\u7528\u8be5\u51fd\u6570\u5c06\u80cc\u666f\u56fe\u50cf\u6dfb\u52a0\u5230\u4e8c\u7ef4\u7801\u4e2d<\/strong><\/h2>\n<p>add_background_to_qrcode(&quot;color_qrcode.png&quot;, &quot;background.png&quot;, &quot;qrcode_with_background.png&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06\u4e8c\u7ef4\u7801\u56fe\u50cf\u53e0\u52a0\u5728\u80cc\u666f\u56fe\u50cf\u4e0a\uff0c\u4f7f\u5176\u66f4\u52a0\u7f8e\u89c2\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001\u7efc\u5408\u793a\u4f8b<\/h2>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7efc\u5408\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u751f\u6210\u4e8c\u7ef4\u7801\u3001\u6dfb\u52a0\u5fae\u4fe1\u516c\u4f17\u53f7logo\u3001\u7f8e\u5316\u4e8c\u7ef4\u7801\u4ee5\u53ca\u6dfb\u52a0\u80cc\u666f\u56fe\u50cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import qrcode<\/p>\n<p>from PIL import Image<\/p>\n<h2><strong>\u751f\u6210\u4e8c\u7ef4\u7801<\/strong><\/h2>\n<p>data = &quot;https:\/\/mp.weixin.qq.com\/&quot;<\/p>\n<p>qr = qrcode.QRCode(<\/p>\n<p>    version=1,<\/p>\n<p>    error_correction=qrcode.constants.ERROR_CORRECT_H,<\/p>\n<p>    box_size=10,<\/p>\n<p>    border=4,<\/p>\n<p>)<\/p>\n<p>qr.add_data(data)<\/p>\n<p>qr.make(fit=True)<\/p>\n<h2><strong>\u521b\u5efa\u5e26\u989c\u8272\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>img = qr.make_image(fill_color=&quot;blue&quot;, back_color=&quot;white&quot;)<\/p>\n<p>img.save(&quot;color_qrcode.png&quot;)<\/p>\n<h2><strong>\u6dfb\u52a0logo\u5230\u4e8c\u7ef4\u7801<\/strong><\/h2>\n<p>def add_logo_to_qrcode(qrcode_path, logo_path, output_path):<\/p>\n<p>    qr_img = Image.open(qrcode_path)<\/p>\n<p>    logo_img = Image.open(logo_path)<\/p>\n<p>    qr_width, qr_height = qr_img.size<\/p>\n<p>    logo_size = qr_width \/\/ 4<\/p>\n<p>    logo_img = logo_img.resize((logo_size, logo_size))<\/p>\n<p>    x = (qr_width - logo_size) \/\/ 2<\/p>\n<p>    y = (qr_height - logo_size) \/\/ 2<\/p>\n<p>    qr_img.paste(logo_img, (x, y), logo_img)<\/p>\n<p>    qr_img.save(output_path)<\/p>\n<p>add_logo_to_qrcode(&quot;color_qrcode.png&quot;, &quot;wechat_logo.png&quot;, &quot;qrcode_with_logo.png&quot;)<\/p>\n<h2><strong>\u6dfb\u52a0\u80cc\u666f\u56fe\u50cf\u5230\u4e8c\u7ef4\u7801<\/strong><\/h2>\n<p>def add_background_to_qrcode(qrcode_path, background_path, output_path):<\/p>\n<p>    qr_img = Image.open(qrcode_path)<\/p>\n<p>    bg_img = Image.open(background_path)<\/p>\n<p>    bg_img = bg_img.resize(qr_img.size)<\/p>\n<p>    bg_img.paste(qr_img, (0, 0), qr_img)<\/p>\n<p>    bg_img.save(output_path)<\/p>\n<p>add_background_to_qrcode(&quot;qrcode_with_logo.png&quot;, &quot;background.png&quot;, &quot;final_qrcode.png&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u4e2a\u7efc\u5408\u793a\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c<strong>\u751f\u6210\u4e00\u4e2a\u7f8e\u89c2\u4e14\u5305\u542b\u5fae\u4fe1\u516c\u4f17\u53f7\u4fe1\u606f\u7684\u4e8c\u7ef4\u7801\u5e76\u4e0d\u590d\u6742\uff0c\u53ea\u9700\u51e0\u6b65\u5373\u53ef\u5b8c\u6210<\/strong>\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u5305\u62ec\u751f\u6210\u4e8c\u7ef4\u7801\u3001\u6dfb\u52a0\u5fae\u4fe1\u516c\u4f17\u53f7logo\u3001\u8c03\u6574\u989c\u8272\u4ee5\u53ca\u6dfb\u52a0\u80cc\u666f\u56fe\u50cf\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u5bf9\u60a8\u6709\u6240\u5e2e\u52a9\uff0c\u8ba9\u60a8\u8f7b\u677e\u638c\u63e1\u5982\u4f55\u901a\u8fc7Python\u751f\u6210\u5e76\u7f8e\u5316\u4e8c\u7ef4\u7801\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u751f\u6210\u5305\u542b\u5fae\u4fe1\u516c\u4f17\u53f7\u4e8c\u7ef4\u7801\u7684\u56fe\u7247\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528<code>qrcode<\/code>\u5e93\u6765\u751f\u6210\u4e8c\u7ef4\u7801\u3002\u9996\u5148\uff0c\u5b89\u88c5\u8fd9\u4e2a\u5e93\uff0c\u5e76\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u793a\u4f8b\u751f\u6210\u4e8c\u7ef4\u7801\uff1a  <\/p>\n<pre><code class=\"language-python\">import qrcode\n\n# \u8f93\u5165\u5fae\u4fe1\u516c\u4f17\u53f7\u7684URL\nurl = &quot;https:\/\/mp.weixin.qq.com\/s\/your_wechat_article&quot;\nqr = qrcode.make(url)\n\n# \u4fdd\u5b58\u4e8c\u7ef4\u7801\u56fe\u50cf\nqr.save(&quot;wechat_qr.png&quot;)\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u4f1a\u521b\u5efa\u4e00\u4e2a\u4e8c\u7ef4\u7801\u56fe\u50cf\uff0c\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u626b\u63cf\u8fd9\u4e2a\u4e8c\u7ef4\u7801\u76f4\u63a5\u8bbf\u95ee\u5fae\u4fe1\u516c\u4f17\u53f7\u3002<\/p>\n<p><strong>\u751f\u6210\u7684\u4e8c\u7ef4\u7801\u56fe\u50cf\u7684\u5c3a\u5bf8\u548c\u6e05\u6670\u5ea6\u5982\u4f55\u8c03\u6574\uff1f<\/strong><br \/>\u5728\u751f\u6210\u4e8c\u7ef4\u7801\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574\u4e8c\u7ef4\u7801\u7684\u5927\u5c0f\u548c\u7ea0\u9519\u7b49\u7ea7\u6765\u6539\u5584\u56fe\u50cf\u8d28\u91cf\u3002\u4f7f\u7528<code>qrcode<\/code>\u5e93\u7684<code>QRCode<\/code>\u7c7b\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u8fd9\u4e9b\u53c2\u6570\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">qr = qrcode.QRCode(\n    version=1,  # \u63a7\u5236\u4e8c\u7ef4\u7801\u7684\u5927\u5c0f\uff0c1\u8868\u793a21x21\u7684\u77e9\u9635\n    error_correction=qrcode.constants.ERROR_CORRECT_H,  # \u8bbe\u7f6e\u9ad8\u7ea0\u9519\u7ea7\u522b\n    box_size=10,  # \u6bcf\u4e2a\u5c0f\u65b9\u683c\u7684\u50cf\u7d20\u5927\u5c0f\n    border=4,  # \u8fb9\u6846\u5bbd\u5ea6\n)\n<\/code><\/pre>\n<p>\u8fd9\u5c06\u751f\u6210\u4e00\u4e2a\u66f4\u6e05\u6670\u4e14\u66f4\u5177\u53ef\u8bfb\u6027\u7684\u4e8c\u7ef4\u7801\u56fe\u50cf\u3002<\/p>\n<p><strong>\u5982\u4f55\u5c06\u751f\u6210\u7684\u4e8c\u7ef4\u7801\u4e0e\u5176\u4ed6\u56fe\u50cf\u6216\u6807\u5fd7\u7ed3\u5408\uff1f<\/strong><br \/>\u4e3a\u4e86\u5c06\u4e8c\u7ef4\u7801\u4e0e\u516c\u53f8\u6807\u5fd7\u6216\u5176\u4ed6\u56fe\u50cf\u7ed3\u5408\uff0c\u53ef\u4ee5\u4f7f\u7528<code>PIL<\/code>\u5e93\uff08Python Imaging Library\uff09\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a  <\/p>\n<pre><code class=\"language-python\">from PIL import Image\n\n# \u6253\u5f00\u4e8c\u7ef4\u7801\u548c\u6807\u5fd7\u56fe\u50cf\nqr_img = Image.open(&quot;wechat_qr.png&quot;)\nlogo = Image.open(&quot;logo.png&quot;)\n\n# \u8c03\u6574\u6807\u5fd7\u7684\u5927\u5c0f\nlogo_size = (50, 50)  # \u6839\u636e\u9700\u8981\u8c03\u6574\u5927\u5c0f\nlogo = logo.resize(logo_size)\n\n# \u8ba1\u7b97\u653e\u7f6e\u4f4d\u7f6e\u5e76\u5408\u5e76\u56fe\u50cf\nqr_img.paste(logo, (qr_img.size[0]\/\/2 - logo_size[0]\/\/2, qr_img.size[1]\/\/2 - logo_size[1]\/\/2), logo)\nqr_img.save(&quot;wechat_qr_with_logo.png&quot;)\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u5236\u4f5c\u51fa\u66f4\u5177\u54c1\u724c\u7279\u8272\u7684\u4e8c\u7ef4\u7801\uff0c\u5438\u5f15\u7528\u6237\u7684\u6ce8\u610f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u4e8c\u7ef4\u7801\u5982\u4f55\u6dfb\u52a0\u5fae\u4fe1\u516c\u4f17\u53f7 Python\u751f\u6210\u4e8c\u7ef4\u7801\u5e76\u6dfb\u52a0\u5fae\u4fe1\u516c\u4f17\u53f7\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528qrcode\u5e93\u751f\u6210\u4e8c [&hellip;]","protected":false},"author":3,"featured_media":1142930,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1142916"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1142916"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1142916\/revisions"}],"predecessor-version":[{"id":1142931,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1142916\/revisions\/1142931"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1142930"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1142916"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1142916"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1142916"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}