{"id":1121427,"date":"2025-01-08T19:09:25","date_gmt":"2025-01-08T11:09:25","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1121427.html"},"modified":"2025-01-08T19:09:27","modified_gmt":"2025-01-08T11:09:27","slug":"python%e5%a6%82%e4%bd%95%e7%94%9f%e6%88%90%e5%8a%a8%e6%80%81%e4%ba%8c%e7%bb%b4%e7%a0%81","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1121427.html","title":{"rendered":"Python\u5982\u4f55\u751f\u6210\u52a8\u6001\u4e8c\u7ef4\u7801"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25083658\/682f84ba-abe7-43c3-b15e-51f8ddc13183.webp\" alt=\"Python\u5982\u4f55\u751f\u6210\u52a8\u6001\u4e8c\u7ef4\u7801\" \/><\/p>\n<p><p> <strong>Python\u751f\u6210\u52a8\u6001\u4e8c\u7ef4\u7801\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528QRCode\u6a21\u5757\u3001\u5229\u7528Pillow\u5e93\u8fdb\u884c\u56fe\u50cf\u5904\u7406\u3001\u7ed3\u5408Flask\u5b9e\u73b0\u52a8\u6001\u751f\u6210\u3002<\/strong> \u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u5e76\u7ed3\u5408\u5b9e\u9645\u5e94\u7528\u573a\u666f\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528Python\u751f\u6210\u52a8\u6001\u4e8c\u7ef4\u7801\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001QRCode\u6a21\u5757<\/p>\n<\/p>\n<p><p>QRCode\u6a21\u5757\u662f\u751f\u6210\u9759\u6001\u548c\u52a8\u6001\u4e8c\u7ef4\u7801\u7684\u4e3b\u8981\u5de5\u5177\u4e4b\u4e00\u3002\u5b83\u7b80\u5355\u6613\u7528\uff0c\u53ef\u4ee5\u751f\u6210\u5404\u79cd\u683c\u5f0f\u7684\u4e8c\u7ef4\u7801\u3002\u4e0b\u9762\u662f\u5177\u4f53\u6b65\u9aa4\u548c\u4ee3\u7801\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u5b89\u88c5QRCode\u548cPillow\u6a21\u5757<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86QRCode\u548cPillow\u6a21\u5757\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\u3001\u751f\u6210\u9759\u6001\u4e8c\u7ef4\u7801<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528QRCode\u6a21\u5757\u751f\u6210\u9759\u6001\u4e8c\u7ef4\u7801\u76f8\u5bf9\u7b80\u5355\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import qrcode<\/p>\n<h2><strong>\u521b\u5efa\u4e8c\u7ef4\u7801\u5bf9\u8c61<\/strong><\/h2>\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<h2><strong>\u6dfb\u52a0\u6570\u636e\u5230\u4e8c\u7ef4\u7801<\/strong><\/h2>\n<p>qr.add_data(&#39;https:\/\/www.example.com&#39;)<\/p>\n<p>qr.make(fit=True)<\/p>\n<h2><strong>\u751f\u6210\u56fe\u50cf<\/strong><\/h2>\n<p>img = qr.make_image(fill=&#39;black&#39;, back_color=&#39;white&#39;)<\/p>\n<h2><strong>\u4fdd\u5b58\u56fe\u50cf<\/strong><\/h2>\n<p>img.save(&#39;static_qr.png&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u751f\u6210\u52a8\u6001\u4e8c\u7ef4\u7801<\/h3>\n<\/p>\n<p><p>\u8981\u751f\u6210\u52a8\u6001\u4e8c\u7ef4\u7801\uff0c\u53ef\u4ee5\u5728QRCode\u6a21\u5757\u7684\u57fa\u7840\u4e0a\uff0c\u7ed3\u5408Flask\u6846\u67b6\u8fdb\u884c\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><p><strong>\u5b89\u88c5Flask\u6a21\u5757\uff1a<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install flask<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>4\u3001\u4f7f\u7528Flask\u751f\u6210\u52a8\u6001\u4e8c\u7ef4\u7801<\/h3>\n<\/p>\n<p><p>\u4e0b\u9762\u662f\u4e00\u4e2a\u751f\u6210\u52a8\u6001\u4e8c\u7ef4\u7801\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from flask import Flask, request, send_file<\/p>\n<p>import qrcode<\/p>\n<p>import io<\/p>\n<p>app = Flask(__name__)<\/p>\n<p>@app.route(&#39;\/generate_qr&#39;)<\/p>\n<p>def generate_qr():<\/p>\n<p>    data = request.args.get(&#39;data&#39;, &#39;&#39;)<\/p>\n<p>    # \u521b\u5efa\u4e8c\u7ef4\u7801\u5bf9\u8c61<\/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>    # \u6dfb\u52a0\u6570\u636e\u5230\u4e8c\u7ef4\u7801<\/p>\n<p>    qr.add_data(data)<\/p>\n<p>    qr.make(fit=True)<\/p>\n<p>    # \u751f\u6210\u56fe\u50cf<\/p>\n<p>    img = qr.make_image(fill=&#39;black&#39;, back_color=&#39;white&#39;)<\/p>\n<p>    # \u5c06\u56fe\u50cf\u4fdd\u5b58\u5230\u5185\u5b58\u4e2d<\/p>\n<p>    img_io = io.BytesIO()<\/p>\n<p>    img.save(img_io, &#39;PNG&#39;)<\/p>\n<p>    img_io.seek(0)<\/p>\n<p>    return send_file(img_io, mimetype=&#39;image\/png&#39;)<\/p>\n<p>if __name__ == &#39;__m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n__&#39;:<\/p>\n<p>    app.run(debug=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u4ee3\u7801\uff0c\u5f53\u4f60\u8bbf\u95ee<code>http:\/\/127.0.0.1:5000\/generate_qr?data=your_data<\/code>\uff0c\u5373\u53ef\u751f\u6210\u5305\u542b<code>your_data<\/code>\u7684\u4e8c\u7ef4\u7801\u56fe\u7247\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u5229\u7528Pillow\u5e93\u8fdb\u884c\u56fe\u50cf\u5904\u7406<\/p>\n<\/p>\n<p><p>Pillow\u5e93\u662fPython\u7684\u56fe\u50cf\u5904\u7406\u5e93\uff0c\u53ef\u4ee5\u5bf9\u751f\u6210\u7684\u4e8c\u7ef4\u7801\u8fdb\u884c\u8fdb\u4e00\u6b65\u5904\u7406\uff0c\u6bd4\u5982\u6dfb\u52a0Logo\u3001\u4fee\u6539\u989c\u8272\u7b49\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u5b89\u88c5Pillow\u6a21\u5757<\/h3>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install Pillow<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u7ed9\u4e8c\u7ef4\u7801\u6dfb\u52a0Logo<\/h3>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5728\u4e8c\u7ef4\u7801\u4e2d\u5fc3\u6dfb\u52a0Logo\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(qr_img_path, logo_img_path, save_path):<\/p>\n<p>    qr_img = Image.open(qr_img_path)<\/p>\n<p>    logo = Image.open(logo_img_path)<\/p>\n<p>    # \u8ba1\u7b97Logo\u7684\u5927\u5c0f\u548c\u4f4d\u7f6e<\/p>\n<p>    qr_width, qr_height = qr_img.size<\/p>\n<p>    logo_size = int(qr_width \/ 4)<\/p>\n<p>    logo = logo.resize((logo_size, logo_size))<\/p>\n<p>    logo_position = ((qr_width - logo_size) \/\/ 2, (qr_height - logo_size) \/\/ 2)<\/p>\n<p>    qr_img.paste(logo, logo_position, logo)<\/p>\n<p>    qr_img.save(save_path)<\/p>\n<h2><strong>\u4f7f\u7528\u793a\u4f8b<\/strong><\/h2>\n<p>add_logo(&#39;static_qr.png&#39;, &#39;logo.png&#39;, &#39;qr_with_logo.png&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u4fee\u6539\u4e8c\u7ef4\u7801\u989c\u8272<\/h3>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4fee\u6539\u4e8c\u7ef4\u7801\u989c\u8272\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import qrcode<\/p>\n<p>from PIL import Image<\/p>\n<h2><strong>\u521b\u5efa\u4e8c\u7ef4\u7801\u5bf9\u8c61<\/strong><\/h2>\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<h2><strong>\u6dfb\u52a0\u6570\u636e\u5230\u4e8c\u7ef4\u7801<\/strong><\/h2>\n<p>qr.add_data(&#39;https:\/\/www.example.com&#39;)<\/p>\n<p>qr.make(fit=True)<\/p>\n<h2><strong>\u751f\u6210\u56fe\u50cf<\/strong><\/h2>\n<p>img = qr.make_image(fill_color=&#39;blue&#39;, back_color=&#39;white&#39;)<\/p>\n<h2><strong>\u4fdd\u5b58\u56fe\u50cf<\/strong><\/h2>\n<p>img.save(&#39;colored_qr.png&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u7ed3\u5408Flask\u5b9e\u73b0\u52a8\u6001\u751f\u6210<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u7ed3\u5408Flask\u6846\u67b6\uff0c\u53ef\u4ee5\u5b9e\u73b0\u52a8\u6001\u751f\u6210\u4e8c\u7ef4\u7801\uff0c\u5e76\u5c06\u5176\u96c6\u6210\u5230Web\u5e94\u7528\u4e2d\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u521b\u5efaFlask\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2aFlask\u5e94\u7528\uff0c\u5e76\u5b9a\u4e49\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u8def\u7531\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from flask import Flask, request, send_file<\/p>\n<p>import qrcode<\/p>\n<p>import io<\/p>\n<p>app = Flask(__name__)<\/p>\n<p>@app.route(&#39;\/generate_qr&#39;)<\/p>\n<p>def generate_qr():<\/p>\n<p>    data = request.args.get(&#39;data&#39;, &#39;&#39;)<\/p>\n<p>    color = request.args.get(&#39;color&#39;, &#39;black&#39;)<\/p>\n<p>    background = request.args.get(&#39;background&#39;, &#39;white&#39;)<\/p>\n<p>    # \u521b\u5efa\u4e8c\u7ef4\u7801\u5bf9\u8c61<\/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>    # \u6dfb\u52a0\u6570\u636e\u5230\u4e8c\u7ef4\u7801<\/p>\n<p>    qr.add_data(data)<\/p>\n<p>    qr.make(fit=True)<\/p>\n<p>    # \u751f\u6210\u56fe\u50cf<\/p>\n<p>    img = qr.make_image(fill_color=color, back_color=background)<\/p>\n<p>    # \u5c06\u56fe\u50cf\u4fdd\u5b58\u5230\u5185\u5b58\u4e2d<\/p>\n<p>    img_io = io.BytesIO()<\/p>\n<p>    img.save(img_io, &#39;PNG&#39;)<\/p>\n<p>    img_io.seek(0)<\/p>\n<p>    return send_file(img_io, mimetype=&#39;image\/png&#39;)<\/p>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    app.run(debug=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u96c6\u6210\u5230Web\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u5c06\u4e0a\u8ff0Flask\u5e94\u7528\u96c6\u6210\u5230\u4f60\u7684Web\u5e94\u7528\u4e2d\uff0c\u5e76\u901a\u8fc7\u524d\u7aef\u9875\u9762\u52a8\u6001\u4f20\u9012\u53c2\u6570\u751f\u6210\u4e8c\u7ef4\u7801\u3002<\/p>\n<\/p>\n<p><p><strong>\u524d\u7aefHTML\u793a\u4f8b\uff1a<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-html\">&lt;!DOCTYPE html&gt;<\/p>\n<p>&lt;html&gt;<\/p>\n<p>&lt;head&gt;<\/p>\n<p>    &lt;title&gt;QR Code Generator&lt;\/title&gt;<\/p>\n<p>&lt;\/head&gt;<\/p>\n<p>&lt;body&gt;<\/p>\n<p>    &lt;h1&gt;Generate QR Code&lt;\/h1&gt;<\/p>\n<p>    &lt;form action=&quot;\/generate_qr&quot; method=&quot;get&quot;&gt;<\/p>\n<p>        &lt;label for=&quot;data&quot;&gt;Data:&lt;\/label&gt;<\/p>\n<p>        &lt;input type=&quot;text&quot; id=&quot;data&quot; name=&quot;data&quot;&gt;&lt;br&gt;&lt;br&gt;<\/p>\n<p>        &lt;label for=&quot;color&quot;&gt;Color:&lt;\/label&gt;<\/p>\n<p>        &lt;input type=&quot;text&quot; id=&quot;color&quot; name=&quot;color&quot; value=&quot;black&quot;&gt;&lt;br&gt;&lt;br&gt;<\/p>\n<p>        &lt;label for=&quot;background&quot;&gt;Background:&lt;\/label&gt;<\/p>\n<p>        &lt;input type=&quot;text&quot; id=&quot;background&quot; name=&quot;background&quot; value=&quot;white&quot;&gt;&lt;br&gt;&lt;br&gt;<\/p>\n<p>        &lt;input type=&quot;submit&quot; value=&quot;Generate&quot;&gt;<\/p>\n<p>    &lt;\/form&gt;<\/p>\n<p>    &lt;img id=&quot;qr_code&quot; src=&quot;&quot; alt=&quot;QR Code&quot;&gt;<\/p>\n<p>&lt;\/body&gt;<\/p>\n<p>&lt;script&gt;<\/p>\n<p>    document.querySelector(&#39;form&#39;).addEventListener(&#39;submit&#39;, function(event) {<\/p>\n<p>        event.preventDefault();<\/p>\n<p>        var data = document.getElementById(&#39;data&#39;).value;<\/p>\n<p>        var color = document.getElementById(&#39;color&#39;).value;<\/p>\n<p>        var background = document.getElementById(&#39;background&#39;).value;<\/p>\n<p>        var img = document.getElementById(&#39;qr_code&#39;);<\/p>\n<p>        img.src = `\/generate_qr?data=${data}&amp;color=${color}&amp;background=${background}`;<\/p>\n<p>    });<\/p>\n<p>&lt;\/script&gt;<\/p>\n<p>&lt;\/html&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0HTML\u9875\u9762\uff0c\u53ef\u4ee5\u52a8\u6001\u751f\u6210\u548c\u663e\u793a\u4e8c\u7ef4\u7801\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u5b9e\u9645\u5e94\u7528\u573a\u666f<\/p>\n<\/p>\n<p><h3>1\u3001\u7535\u5b50\u5546\u52a1<\/h3>\n<\/p>\n<p><p>\u5728\u7535\u5b50\u5546\u52a1\u7f51\u7ad9\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e8c\u7ef4\u7801\u751f\u6210\u6280\u672f\u6765\u521b\u5efa\u4f18\u60e0\u5238\u3001\u5546\u54c1\u4fe1\u606f\u7b49\u4e8c\u7ef4\u7801\uff0c\u65b9\u4fbf\u7528\u6237\u901a\u8fc7\u626b\u7801\u83b7\u53d6\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u79fb\u52a8\u652f\u4ed8<\/h3>\n<\/p>\n<p><p>\u5728\u79fb\u52a8\u652f\u4ed8\u5e94\u7528\u4e2d\uff0c\u52a8\u6001\u751f\u6210\u4e8c\u7ef4\u7801\u53ef\u4ee5\u7528\u4e8e\u521b\u5efa\u652f\u4ed8\u94fe\u63a5\u3001\u6536\u6b3e\u7801\u7b49\uff0c\u63d0\u9ad8\u7528\u6237\u652f\u4ed8\u7684\u4fbf\u5229\u6027\u3002<\/p>\n<\/p>\n<p><h3>3\u3001\u4fe1\u606f\u5171\u4eab<\/h3>\n<\/p>\n<p><p>\u5728\u793e\u4ea4\u5a92\u4f53\u3001\u540d\u7247\u7b49\u573a\u666f\u4e2d\uff0c\u901a\u8fc7\u751f\u6210\u4e8c\u7ef4\u7801\u53ef\u4ee5\u65b9\u4fbf\u5730\u5171\u4eab\u4e2a\u4eba\u4fe1\u606f\u3001\u7f51\u5740\u7b49\uff0c\u63d0\u9ad8\u4fe1\u606f\u4f20\u9012\u7684\u6548\u7387\u3002<\/p>\n<\/p>\n<p><h3>4\u3001\u7269\u6d41\u8ddf\u8e2a<\/h3>\n<\/p>\n<p><p>\u5728\u7269\u6d41\u884c\u4e1a\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u751f\u6210\u5305\u542b\u7269\u6d41\u4fe1\u606f\u7684\u4e8c\u7ef4\u7801\uff0c\u5b9e\u73b0\u5305\u88f9\u7684\u52a8\u6001\u8ddf\u8e2a\u548c\u7ba1\u7406\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u6211\u4eec\u8be6\u7ec6\u4e86\u89e3\u4e86Python\u751f\u6210\u52a8\u6001\u4e8c\u7ef4\u7801\u7684\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528QRCode\u6a21\u5757\u3001\u7ed3\u5408Pillow\u5e93\u8fdb\u884c\u56fe\u50cf\u5904\u7406\u3001\u5229\u7528Flask\u5b9e\u73b0\u52a8\u6001\u751f\u6210\u7b49\u3002\u5e0c\u671b\u8fd9\u4e9b\u5185\u5bb9\u80fd\u5e2e\u52a9\u4f60\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u7075\u6d3b\u8fd0\u7528\u4e8c\u7ef4\u7801\u6280\u672f\uff0c\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\u548c\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528\u5e93\u751f\u6210\u52a8\u6001\u4e8c\u7ef4\u7801\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u751f\u6210\u52a8\u6001\u4e8c\u7ef4\u7801\u53ef\u4ee5\u4f7f\u7528<code>qrcode<\/code>\u548c<code>PIL<\/code>\uff08Pillow\uff09\u5e93\u3002\u9996\u5148\uff0c\u786e\u4fdd\u5b89\u88c5\u4e86\u8fd9\u4e24\u4e2a\u5e93\u3002\u53ef\u4ee5\u901a\u8fc7<code>pip install qrcode[pil]<\/code>\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\u3002\u63a5\u4e0b\u6765\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u4ee3\u7801\u751f\u6210\u4e8c\u7ef4\u7801\uff1a  <\/p>\n<pre><code class=\"language-python\">import qrcode\nfrom PIL import Image\n\ndata = &quot;https:\/\/example.com&quot;  # \u60a8\u5e0c\u671b\u4e8c\u7ef4\u7801\u6307\u5411\u7684\u7f51\u5740\nqr = qrcode.QRCode(version=1, box_size=10, border=5)\nqr.add_data(data)\nqr.make(fit=True)\n\nimg = qr.make_image(fill=&#39;black&#39;, back_color=&#39;white&#39;)\nimg.save(&#39;dynamic_qr.png&#39;)\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u521b\u5efa\u4e86\u4e00\u4e2a\u6307\u5411\u7279\u5b9a\u7f51\u5740\u7684\u4e8c\u7ef4\u7801\u3002<\/p>\n<p><strong>\u5982\u4f55\u66f4\u65b0\u52a8\u6001\u4e8c\u7ef4\u7801\u6307\u5411\u7684\u94fe\u63a5\uff1f<\/strong><br \/>\u52a8\u6001\u4e8c\u7ef4\u7801\u7684\u9b45\u529b\u5728\u4e8e\u60a8\u53ef\u4ee5\u968f\u65f6\u66f4\u65b0\u5176\u6307\u5411\u7684\u94fe\u63a5\u800c\u65e0\u9700\u91cd\u65b0\u751f\u6210\u4e8c\u7ef4\u7801\u3002\u8fd9\u901a\u5e38\u901a\u8fc7\u4e00\u4e2a\u77ed\u94fe\u63a5\u670d\u52a1\u6765\u5b9e\u73b0\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u5982Bitly\u6216\u5176\u4ed6\u77ed\u94fe\u63a5\u751f\u6210\u5668\uff0c\u751f\u6210\u4e00\u4e2a\u6307\u5411\u60a8\u7f51\u9875\u7684\u77ed\u94fe\u63a5\uff0c\u5e76\u5c06\u5176\u653e\u5165\u4e8c\u7ef4\u7801\u4e2d\u3002\u5f53\u60a8\u9700\u8981\u66f4\u6539\u94fe\u63a5\u65f6\uff0c\u53ea\u9700\u66f4\u65b0\u77ed\u94fe\u63a5\u7684\u76ee\u6807\u7f51\u5740\u5373\u53ef\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u8bbe\u7f6e\u4e8c\u7ef4\u7801\u7684\u6837\u5f0f\u548c\u989c\u8272\uff1f<\/strong><br \/>\u60a8\u53ef\u4ee5\u901a\u8fc7<code>make_image()<\/code>\u65b9\u6cd5\u81ea\u5b9a\u4e49\u4e8c\u7ef4\u7801\u7684\u6837\u5f0f\u548c\u989c\u8272\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6765\u66f4\u6539\u4e8c\u7ef4\u7801\u7684\u989c\u8272\uff1a  <\/p>\n<pre><code class=\"language-python\">img = qr.make_image(fill=&#39;blue&#39;, back_color=&#39;yellow&#39;)\n<\/code><\/pre>\n<p>\u8fd9\u5c06\u751f\u6210\u4e00\u4e2a\u84dd\u8272\u524d\u666f\u548c\u9ec4\u8272\u80cc\u666f\u7684\u4e8c\u7ef4\u7801\u3002\u901a\u8fc7\u8c03\u6574<code>fill<\/code>\u548c<code>back_color<\/code>\u53c2\u6570\uff0c\u60a8\u53ef\u4ee5\u5b9e\u73b0\u591a\u79cd\u989c\u8272\u7ec4\u5408\uff0c\u6ee1\u8db3\u4e0d\u540c\u7684\u8bbe\u8ba1\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u751f\u6210\u52a8\u6001\u4e8c\u7ef4\u7801\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528QRCode\u6a21\u5757\u3001\u5229\u7528Pillow\u5e93\u8fdb\u884c\u56fe\u50cf\u5904\u7406\u3001\u7ed3\u5408Flask\u5b9e\u73b0\u52a8 [&hellip;]","protected":false},"author":3,"featured_media":1121435,"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\/1121427"}],"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=1121427"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1121427\/revisions"}],"predecessor-version":[{"id":1121438,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1121427\/revisions\/1121438"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1121435"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1121427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1121427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1121427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}