{"id":1126827,"date":"2025-01-08T20:04:43","date_gmt":"2025-01-08T12:04:43","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1126827.html"},"modified":"2025-01-08T20:04:46","modified_gmt":"2025-01-08T12:04:46","slug":"python%e4%bb%a3%e7%a0%81%e5%a6%82%e4%bd%95%e5%81%9a%e6%88%90%e4%ba%8c%e7%bb%b4%e7%a0%81","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1126827.html","title":{"rendered":"python\u4ee3\u7801\u5982\u4f55\u505a\u6210\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\/25091010\/6b251b3f-90be-4c36-be00-a0f1f9b08185.webp\" alt=\"python\u4ee3\u7801\u5982\u4f55\u505a\u6210\u4e8c\u7ef4\u7801\" \/><\/p>\n<p><p> <strong>Python\u4ee3\u7801\u5982\u4f55\u505a\u6210\u4e8c\u7ef4\u7801<\/strong><\/p>\n<\/p>\n<p><p><strong>\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u6b65\u9aa4\u6709\uff1a\u9009\u62e9\u5408\u9002\u7684\u5e93\u3001\u7f16\u5199\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u4ee3\u7801\u3001\u4fdd\u5b58\u548c\u5c55\u793a\u4e8c\u7ef4\u7801\u3001\u4f18\u5316\u4e8c\u7ef4\u7801\u7684\u5185\u5bb9\u3001\u6dfb\u52a0\u5bb9\u9519\u673a\u5236\u3002<\/strong> \u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Python\u751f\u6210\u4e8c\u7ef4\u7801\uff0c\u5e76\u4ecb\u7ecd\u4e00\u4e9b\u9ad8\u7ea7\u6280\u5de7\u548c\u4f18\u5316\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u9009\u62e9\u5408\u9002\u7684\u5e93<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u6709\u51e0\u4e2a\u6d41\u884c\u7684\u5e93\u53ef\u4ee5\u7528\u4e8e\u751f\u6210\u4e8c\u7ef4\u7801\uff0c\u5176\u4e2d\u6700\u5e38\u7528\u7684\u662f<code>qrcode<\/code>\u548c<code>pyqrcode<\/code>\u3002\u8fd9\u4e24\u4e2a\u5e93\u90fd\u53ef\u4ee5\u8f7b\u677e\u751f\u6210\u4e8c\u7ef4\u7801\uff0c\u4f46\u5728\u529f\u80fd\u548c\u4f7f\u7528\u573a\u666f\u4e0a\u6709\u4e9b\u5fae\u5dee\u5f02\u3002<\/p>\n<\/p>\n<p><h4>1. <code>qrcode<\/code>\u5e93<\/h4>\n<\/p>\n<p><p><code>qrcode<\/code>\u5e93\u662f\u4e00\u4e2a\u7b80\u5355\u4e14\u529f\u80fd\u5f3a\u5927\u7684\u5e93\uff0c\u652f\u6301\u591a\u79cd\u914d\u7f6e\u9009\u9879\u3002\u5b83\u53ef\u4ee5\u5c06\u6587\u672c\u3001URL\u7b49\u4fe1\u606f\u8f6c\u6362\u4e3a\u4e8c\u7ef4\u7801\uff0c\u5e76\u4e14\u53ef\u4ee5\u81ea\u5b9a\u4e49\u4e8c\u7ef4\u7801\u7684\u5927\u5c0f\u3001\u989c\u8272\u7b49\u3002<\/p>\n<\/p>\n<p><h4>2. <code>pyqrcode<\/code>\u5e93<\/h4>\n<\/p>\n<p><p><code>pyqrcode<\/code>\u5e93\u662f\u53e6\u4e00\u4e2a\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u597d\u9009\u62e9\uff0c\u5b83\u652f\u6301\u751f\u6210\u9ad8\u8d28\u91cf\u7684\u4e8c\u7ef4\u7801\uff0c\u540c\u65f6\u4e5f\u53ef\u4ee5\u5c06\u4e8c\u7ef4\u7801\u4fdd\u5b58\u4e3a\u591a\u79cd\u683c\u5f0f\uff0c\u6bd4\u5982PNG\u3001SVG\u7b49\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u7f16\u5199\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u4ee3\u7801<\/h3>\n<\/p>\n<p><h4>1. \u4f7f\u7528<code>qrcode<\/code>\u5e93\u751f\u6210\u4e8c\u7ef4\u7801<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5<code>qrcode<\/code>\u5e93\uff0c\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 qrcode[pil]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u53ef\u4ee5\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684Python\u811a\u672c\u6765\u751f\u6210\u4e8c\u7ef4\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import qrcode<\/p>\n<h2><strong>\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u5185\u5bb9<\/strong><\/h2>\n<p>data = &quot;https:\/\/example.com&quot;<\/p>\n<h2><strong>\u521b\u5efaQRCode\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>\u5411QRCode\u5bf9\u8c61\u4e2d\u6dfb\u52a0\u6570\u636e<\/strong><\/h2>\n<p>qr.add_data(data)<\/p>\n<p>qr.make(fit=True)<\/p>\n<h2><strong>\u521b\u5efa\u4e8c\u7ef4\u7801\u56fe\u50cf<\/strong><\/h2>\n<p>img = qr.make_image(fill_color=&quot;black&quot;, back_color=&quot;white&quot;)<\/p>\n<h2><strong>\u4fdd\u5b58\u4e8c\u7ef4\u7801\u56fe\u50cf<\/strong><\/h2>\n<p>img.save(&quot;qrcode.png&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528<code>pyqrcode<\/code>\u5e93\u751f\u6210\u4e8c\u7ef4\u7801<\/h4>\n<\/p>\n<p><p>\u540c\u6837\u7684\uff0c\u6211\u4eec\u9700\u8981\u5148\u5b89\u88c5<code>pyqrcode<\/code>\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pyqrcode<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u7f16\u5199\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pyqrcode<\/p>\n<h2><strong>\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u5185\u5bb9<\/strong><\/h2>\n<p>data = &quot;https:\/\/example.com&quot;<\/p>\n<h2><strong>\u521b\u5efaQRCode\u5bf9\u8c61<\/strong><\/h2>\n<p>qr = pyqrcode.create(data)<\/p>\n<h2><strong>\u5c06\u4e8c\u7ef4\u7801\u4fdd\u5b58\u4e3aPNG\u6587\u4ef6<\/strong><\/h2>\n<p>qr.png(&quot;qrcode.png&quot;, scale=6)<\/p>\n<h2><strong>\u6216\u8005\u4fdd\u5b58\u4e3aSVG\u6587\u4ef6<\/strong><\/h2>\n<p>qr.svg(&quot;qrcode.svg&quot;, scale=6)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u4fdd\u5b58\u548c\u5c55\u793a\u4e8c\u7ef4\u7801<\/h3>\n<\/p>\n<p><p>\u4fdd\u5b58\u4e8c\u7ef4\u7801\u7684\u683c\u5f0f\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u9009\u62e9\uff0c\u5e38\u89c1\u7684\u683c\u5f0f\u6709PNG\u548cSVG\u3002PNG\u683c\u5f0f\u9002\u7528\u4e8e\u5927\u591a\u6570\u5e94\u7528\u573a\u666f\uff0c\u800cSVG\u683c\u5f0f\u5219\u9002\u7528\u4e8e\u9700\u8981\u9ad8\u8d28\u91cf\u77e2\u91cf\u56fe\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h4>1. \u4fdd\u5b58\u4e3aPNG\u683c\u5f0f<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528<code>qrcode<\/code>\u5e93\u751f\u6210\u7684\u4e8c\u7ef4\u7801\u53ef\u4ee5\u76f4\u63a5\u4fdd\u5b58\u4e3aPNG\u683c\u5f0f\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">img.save(&quot;qrcode.png&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528<code>pyqrcode<\/code>\u5e93\u751f\u6210\u7684\u4e8c\u7ef4\u7801\u4e5f\u53ef\u4ee5\u4fdd\u5b58\u4e3aPNG\u683c\u5f0f\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">qr.png(&quot;qrcode.png&quot;, scale=6)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4fdd\u5b58\u4e3aSVG\u683c\u5f0f<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528<code>pyqrcode<\/code>\u5e93\u751f\u6210\u7684\u4e8c\u7ef4\u7801\u53ef\u4ee5\u4fdd\u5b58\u4e3aSVG\u683c\u5f0f\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">qr.svg(&quot;qrcode.svg&quot;, scale=6)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u4f18\u5316\u4e8c\u7ef4\u7801\u7684\u5185\u5bb9<\/h3>\n<\/p>\n<p><p>\u5728\u751f\u6210\u4e8c\u7ef4\u7801\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u5bf9\u4e8c\u7ef4\u7801\u7684\u5185\u5bb9\u8fdb\u884c\u4f18\u5316\uff0c\u4ee5\u63d0\u9ad8\u4e8c\u7ef4\u7801\u7684\u53ef\u626b\u63cf\u6027\u548c\u4fe1\u606f\u627f\u8f7d\u80fd\u529b\u3002<\/p>\n<\/p>\n<p><h4>1. \u538b\u7f29\u5185\u5bb9<\/h4>\n<\/p>\n<p><p>\u4e8c\u7ef4\u7801\u7684\u5bb9\u91cf\u662f\u6709\u9650\u7684\uff0c\u5982\u679c\u5185\u5bb9\u8fc7\u591a\uff0c\u4e8c\u7ef4\u7801\u7684\u5c3a\u5bf8\u4f1a\u53d8\u5927\uff0c\u626b\u63cf\u96be\u5ea6\u4e5f\u4f1a\u589e\u52a0\u3002\u56e0\u6b64\uff0c\u53ef\u4ee5\u901a\u8fc7\u538b\u7f29\u5185\u5bb9\u6765\u4f18\u5316\u4e8c\u7ef4\u7801\u3002\u6bd4\u5982\uff0c\u5bf9\u4e8eURL\uff0c\u53ef\u4ee5\u4f7f\u7528URL\u7f29\u77ed\u670d\u52a1\uff08\u5982bit.ly\uff09\u6765\u7f29\u77edURL\u3002<\/p>\n<\/p>\n<p><h4>2. \u4f7f\u7528\u77ed\u94fe\u63a5<\/h4>\n<\/p>\n<p><p>\u77ed\u94fe\u63a5\u4e0d\u4ec5\u53ef\u4ee5\u51cf\u5c11\u4e8c\u7ef4\u7801\u7684\u5c3a\u5bf8\uff0c\u8fd8\u53ef\u4ee5\u65b9\u4fbf\u8ffd\u8e2a\u548c\u5206\u6790\u4e8c\u7ef4\u7801\u7684\u626b\u63cf\u6570\u636e\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5c06\u957f\u94fe\u63a5\u8f6c\u6362\u4e3a\u77ed\u94fe\u63a5\uff0c\u518d\u751f\u6210\u4e8c\u7ef4\u7801\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u6dfb\u52a0\u5bb9\u9519\u673a\u5236<\/h3>\n<\/p>\n<p><p>\u4e8c\u7ef4\u7801\u5728\u751f\u6210\u548c\u4f7f\u7528\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u4f1a\u9047\u5230\u6c61\u635f\u3001\u906e\u6321\u7b49\u60c5\u51b5\uff0c\u8fd9\u65f6\u5019\u5c31\u9700\u8981\u4f7f\u7528\u4e8c\u7ef4\u7801\u7684\u5bb9\u9519\u673a\u5236\u3002\u4e8c\u7ef4\u7801\u7684\u5bb9\u9519\u673a\u5236\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u9519\u8bef\u7ea0\u6b63\u7b49\u7ea7\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><h4>1. \u9519\u8bef\u7ea0\u6b63\u7b49\u7ea7<\/h4>\n<\/p>\n<p><p>\u4e8c\u7ef4\u7801\u6709\u56db\u79cd\u9519\u8bef\u7ea0\u6b63\u7b49\u7ea7\uff0c\u5206\u522b\u662f\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>L<\/strong>\uff1a\u4f4e\u7b49\u7ea7\uff0c\u5927\u7ea6\u53ef\u4ee5\u7ea0\u6b637%\u7684\u9519\u8bef<\/li>\n<li><strong>M<\/strong>\uff1a\u4e2d\u7b49\u7ea7\uff0c\u5927\u7ea6\u53ef\u4ee5\u7ea0\u6b6315%\u7684\u9519\u8bef<\/li>\n<li><strong>Q<\/strong>\uff1a\u4e2d\u9ad8\u7b49\u7ea7\uff0c\u5927\u7ea6\u53ef\u4ee5\u7ea0\u6b6325%\u7684\u9519\u8bef<\/li>\n<li><strong>H<\/strong>\uff1a\u9ad8\u7b49\u7ea7\uff0c\u5927\u7ea6\u53ef\u4ee5\u7ea0\u6b6330%\u7684\u9519\u8bef<\/li>\n<\/ul>\n<p><p>\u5728\u4f7f\u7528<code>qrcode<\/code>\u5e93\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e<code>error_correction<\/code>\u53c2\u6570\u6765\u6307\u5b9a\u9519\u8bef\u7ea0\u6b63\u7b49\u7ea7\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">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><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4f7f\u7528<code>pyqrcode<\/code>\u5e93\u65f6\uff0c\u4e5f\u53ef\u4ee5\u8bbe\u7f6e\u9519\u8bef\u7ea0\u6b63\u7b49\u7ea7\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">qr = pyqrcode.create(data, error=&#39;H&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u751f\u6210\u5e26Logo\u7684\u4e8c\u7ef4\u7801<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u589e\u52a0\u4e8c\u7ef4\u7801\u7684\u54c1\u724c\u8bc6\u522b\u5ea6\uff0c\u53ef\u4ee5\u5728\u4e8c\u7ef4\u7801\u4e2d\u6dfb\u52a0Logo\u3002\u6dfb\u52a0Logo\u7684\u8fc7\u7a0b\u9700\u8981\u4f7f\u7528\u56fe\u50cf\u5904\u7406\u5e93\uff0c\u5982Pillow\u3002<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u5b89\u88c5Pillow\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pillow<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u7f16\u5199\u751f\u6210\u5e26Logo\u7684\u4e8c\u7ef4\u7801\u7684\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>\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u5185\u5bb9<\/strong><\/h2>\n<p>data = &quot;https:\/\/example.com&quot;<\/p>\n<h2><strong>\u521b\u5efaQRCode\u5bf9\u8c61<\/strong><\/h2>\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<h2><strong>\u5411QRCode\u5bf9\u8c61\u4e2d\u6dfb\u52a0\u6570\u636e<\/strong><\/h2>\n<p>qr.add_data(data)<\/p>\n<p>qr.make(fit=True)<\/p>\n<h2><strong>\u521b\u5efa\u4e8c\u7ef4\u7801\u56fe\u50cf<\/strong><\/h2>\n<p>img = qr.make_image(fill_color=&quot;black&quot;, back_color=&quot;white&quot;)<\/p>\n<h2><strong>\u6253\u5f00Logo\u56fe\u50cf<\/strong><\/h2>\n<p>logo = Image.open(&quot;logo.png&quot;)<\/p>\n<h2><strong>\u8ba1\u7b97Logo\u7684\u5c3a\u5bf8<\/strong><\/h2>\n<p>logo_size = 100<\/p>\n<p>logo = logo.resize((logo_size, logo_size), Image.ANTIALIAS)<\/p>\n<h2><strong>\u8ba1\u7b97Logo\u7684\u4f4d\u7f6e<\/strong><\/h2>\n<p>img_w, img_h = img.size<\/p>\n<p>logo_w, logo_h = logo.size<\/p>\n<p>x = (img_w - logo_w) \/\/ 2<\/p>\n<p>y = (img_h - logo_h) \/\/ 2<\/p>\n<h2><strong>\u5c06Logo\u7c98\u8d34\u5230\u4e8c\u7ef4\u7801\u56fe\u50cf\u4e0a<\/strong><\/h2>\n<p>img.paste(logo, (x, y), logo)<\/p>\n<h2><strong>\u4fdd\u5b58\u5e26Logo\u7684\u4e8c\u7ef4\u7801\u56fe\u50cf<\/strong><\/h2>\n<p>img.save(&quot;qrcode_with_logo.png&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u52a8\u6001\u4e8c\u7ef4\u7801<\/h3>\n<\/p>\n<p><p>\u52a8\u6001\u4e8c\u7ef4\u7801\u662f\u4e00\u79cd\u53ef\u4ee5\u5728\u4e0d\u6539\u53d8\u4e8c\u7ef4\u7801\u56fe\u50cf\u7684\u60c5\u51b5\u4e0b\uff0c\u52a8\u6001\u6539\u53d8\u4e8c\u7ef4\u7801\u5185\u5bb9\u7684\u6280\u672f\u3002\u52a8\u6001\u4e8c\u7ef4\u7801\u901a\u5e38\u4f7f\u7528\u77ed\u94fe\u63a5\u670d\u52a1\uff0c\u5c06\u4e8c\u7ef4\u7801\u5185\u5bb9\u6307\u5411\u4e00\u4e2a\u53ef\u7f16\u8f91\u7684\u77ed\u94fe\u63a5\u3002<\/p>\n<\/p>\n<p><h4>1. \u751f\u6210\u77ed\u94fe\u63a5<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u5728\u7ebf\u77ed\u94fe\u63a5\u670d\u52a1\uff08\u5982bit.ly\u3001tinyurl\u7b49\uff09\u751f\u6210\u77ed\u94fe\u63a5\u3002\u5c06\u957f\u94fe\u63a5\u8f6c\u6362\u4e3a\u77ed\u94fe\u63a5\u540e\uff0c\u518d\u751f\u6210\u4e8c\u7ef4\u7801\u3002<\/p>\n<\/p>\n<p><h4>2. \u66f4\u65b0\u77ed\u94fe\u63a5<\/h4>\n<\/p>\n<p><p>\u901a\u8fc7\u77ed\u94fe\u63a5\u670d\u52a1\u7684\u7ba1\u7406\u540e\u53f0\uff0c\u53ef\u4ee5\u66f4\u65b0\u77ed\u94fe\u63a5\u7684\u76ee\u6807\u5730\u5740\uff0c\u4ece\u800c\u5b9e\u73b0\u52a8\u6001\u4e8c\u7ef4\u7801\u7684\u6548\u679c\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u5e94\u7528\u573a\u666f<\/h3>\n<\/p>\n<p><p>\u4e8c\u7ef4\u7801\u5e7f\u6cdb\u5e94\u7528\u4e8e\u5404\u79cd\u573a\u666f\uff0c\u5982\u540d\u7247\u3001\u652f\u4ed8\u3001\u5e7f\u544a\u3001\u7f51\u7ad9\u767b\u5f55\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u5e94\u7528\u573a\u666f\u53ca\u5176\u5b9e\u73b0\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h4>1. \u540d\u7247\u4e8c\u7ef4\u7801<\/h4>\n<\/p>\n<p><p>\u540d\u7247\u4e8c\u7ef4\u7801\u901a\u5e38\u5305\u542b\u4e2a\u4eba\u6216\u516c\u53f8\u7684\u8054\u7cfb\u65b9\u5f0f\uff0c\u53ef\u4ee5\u4f7f\u7528vCard\u683c\u5f0f\u751f\u6210\u4e8c\u7ef4\u7801\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import qrcode<\/p>\n<h2><strong>\u751f\u6210vCard\u683c\u5f0f\u7684\u5185\u5bb9<\/strong><\/h2>\n<p>data = &quot;&quot;&quot;<\/p>\n<p>BEGIN:VCARD<\/p>\n<p>VERSION:3.0<\/p>\n<p>FN:John Doe<\/p>\n<p>ORG:Example Inc.<\/p>\n<p>TEL:123456789<\/p>\n<p>EM<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>L:john.doe@example.com<\/p>\n<p>END:VCARD<\/p>\n<p>&quot;&quot;&quot;<\/p>\n<h2><strong>\u521b\u5efaQRCode\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>\u5411QRCode\u5bf9\u8c61\u4e2d\u6dfb\u52a0\u6570\u636e<\/strong><\/h2>\n<p>qr.add_data(data)<\/p>\n<p>qr.make(fit=True)<\/p>\n<h2><strong>\u521b\u5efa\u4e8c\u7ef4\u7801\u56fe\u50cf<\/strong><\/h2>\n<p>img = qr.make_image(fill_color=&quot;black&quot;, back_color=&quot;white&quot;)<\/p>\n<h2><strong>\u4fdd\u5b58\u4e8c\u7ef4\u7801\u56fe\u50cf<\/strong><\/h2>\n<p>img.save(&quot;vcard_qrcode.png&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u652f\u4ed8\u4e8c\u7ef4\u7801<\/h4>\n<\/p>\n<p><p>\u652f\u4ed8\u4e8c\u7ef4\u7801\u901a\u5e38\u5305\u542b\u652f\u4ed8\u4fe1\u606f\uff0c\u5982\u652f\u4ed8\u5b9d\u3001\u5fae\u4fe1\u652f\u4ed8\u7b49\u3002\u53ef\u4ee5\u4f7f\u7528\u652f\u4ed8\u5e73\u53f0\u63d0\u4f9b\u7684API\u751f\u6210\u652f\u4ed8\u4e8c\u7ef4\u7801\u3002<\/p>\n<\/p>\n<p><h4>3. \u5e7f\u544a\u4e8c\u7ef4\u7801<\/h4>\n<\/p>\n<p><p>\u5e7f\u544a\u4e8c\u7ef4\u7801\u901a\u5e38\u5305\u542b\u4ea7\u54c1\u4fe1\u606f\u3001\u4f18\u60e0\u5238\u7b49\uff0c\u53ef\u4ee5\u901a\u8fc7\u77ed\u94fe\u63a5\u670d\u52a1\u751f\u6210\u4e8c\u7ef4\u7801\uff0c\u5e76\u901a\u8fc7\u5e7f\u544a\u6295\u653e\u3002<\/p>\n<\/p>\n<p><h4>4. \u7f51\u7ad9\u767b\u5f55\u4e8c\u7ef4\u7801<\/h4>\n<\/p>\n<p><p>\u7f51\u7ad9\u767b\u5f55\u4e8c\u7ef4\u7801\u53ef\u4ee5\u7528\u4e8e\u5feb\u901f\u767b\u5f55\u7f51\u7ad9\uff0c\u901a\u5e38\u5305\u542b\u767b\u5f55\u51ed\u8bc1\u4fe1\u606f\u3002\u53ef\u4ee5\u4f7f\u7528\u7f51\u7ad9\u540e\u53f0\u751f\u6210\u767b\u5f55\u4e8c\u7ef4\u7801\uff0c\u5e76\u901a\u8fc7\u626b\u63cf\u4e8c\u7ef4\u7801\u5feb\u901f\u767b\u5f55\u3002<\/p>\n<\/p>\n<p><h3>\u4e5d\u3001\u4f18\u5316\u548c\u6ce8\u610f\u4e8b\u9879<\/h3>\n<\/p>\n<p><h4>1. \u786e\u4fdd\u4e8c\u7ef4\u7801\u7684\u53ef\u626b\u63cf\u6027<\/h4>\n<\/p>\n<p><p>\u4e8c\u7ef4\u7801\u7684\u53ef\u626b\u63cf\u6027\u662f\u975e\u5e38\u91cd\u8981\u7684\uff0c\u751f\u6210\u4e8c\u7ef4\u7801\u65f6\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u5bf9\u6bd4\u5ea6<\/strong>\uff1a\u786e\u4fdd\u4e8c\u7ef4\u7801\u7684\u524d\u666f\u8272\u548c\u80cc\u666f\u8272\u6709\u8db3\u591f\u7684\u5bf9\u6bd4\u5ea6\uff0c\u907f\u514d\u4f7f\u7528\u76f8\u8fd1\u7684\u989c\u8272\u3002<\/li>\n<li><strong>\u5c3a\u5bf8<\/strong>\uff1a\u4e8c\u7ef4\u7801\u7684\u5c3a\u5bf8\u4e0d\u5b9c\u8fc7\u5c0f\uff0c\u5efa\u8bae\u81f3\u5c11\u4e3a1\u82f1\u5bf8\uff082.54\u5398\u7c73\uff09\u3002<\/li>\n<li><strong>\u8fb9\u6846<\/strong>\uff1a\u4e8c\u7ef4\u7801\u5468\u56f4\u9700\u8981\u7559\u6709\u4e00\u5b9a\u7684\u8fb9\u6846\uff0c\u901a\u5e38\u4e3a4\u4e2a\u5355\u4f4d\u7684\u5bbd\u5ea6\u3002<\/li>\n<li><strong>\u5185\u5bb9<\/strong>\uff1a\u907f\u514d\u5728\u4e8c\u7ef4\u7801\u4e2d\u5305\u542b\u8fc7\u591a\u7684\u5185\u5bb9\uff0c\u53ef\u4ee5\u901a\u8fc7\u538b\u7f29\u548c\u77ed\u94fe\u63a5\u4f18\u5316\u5185\u5bb9\u3002<\/li>\n<\/ul>\n<p><h4>2. \u6d4b\u8bd5\u4e8c\u7ef4\u7801<\/h4>\n<\/p>\n<p><p>\u5728\u751f\u6210\u4e8c\u7ef4\u7801\u540e\uff0c\u5efa\u8bae\u4f7f\u7528\u591a\u79cd\u8bbe\u5907\u548c\u5e94\u7528\u7a0b\u5e8f\u8fdb\u884c\u6d4b\u8bd5\uff0c\u786e\u4fdd\u4e8c\u7ef4\u7801\u7684\u53ef\u626b\u63cf\u6027\u548c\u5185\u5bb9\u7684\u6b63\u786e\u6027\u3002<\/p>\n<\/p>\n<p><h4>3. \u5b89\u5168\u6027<\/h4>\n<\/p>\n<p><p>\u5728\u4f7f\u7528\u4e8c\u7ef4\u7801\u4f20\u9012\u654f\u611f\u4fe1\u606f\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u5b89\u5168\u6027\u3002\u907f\u514d\u5c06\u654f\u611f\u4fe1\u606f\u76f4\u63a5\u5d4c\u5165\u4e8c\u7ef4\u7801\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u52a0\u5bc6\u6280\u672f\u6216\u77ed\u94fe\u63a5\u670d\u52a1\u8fdb\u884c\u4fdd\u62a4\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u76f8\u4fe1\u5927\u5bb6\u5df2\u7ecf\u4e86\u89e3\u4e86\u5982\u4f55\u4f7f\u7528Python\u751f\u6210\u4e8c\u7ef4\u7801\uff0c\u5e76\u638c\u63e1\u4e86\u4e00\u4e9b\u9ad8\u7ea7\u6280\u5de7\u548c\u4f18\u5316\u65b9\u6cd5\u3002\u5e0c\u671b\u8fd9\u4e9b\u5185\u5bb9\u5bf9\u5927\u5bb6\u6709\u6240\u5e2e\u52a9\uff0c\u80fd\u591f\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u751f\u6210\u9ad8\u8d28\u91cf\u7684\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\u4e8c\u7ef4\u7801\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u5982<code>qrcode<\/code>\u6765\u751f\u6210\u4e8c\u7ef4\u7801\u3002\u5b89\u88c5\u8be5\u5e93\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u8fd0\u884c<code>pip install qrcode[pil]<\/code>\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u751f\u6210\u4e8c\u7ef4\u7801\uff1a<\/p>\n<pre><code class=\"language-python\">import qrcode\n\n# \u521b\u5efa\u4e8c\u7ef4\u7801\u5bf9\u8c61\nqr = qrcode.QRCode(version=1, box_size=10, border=5)\nqr.add_data(&#39;https:\/\/www.example.com&#39;)  # \u8fd9\u91cc\u53ef\u4ee5\u6dfb\u52a0\u4f60\u60f3\u7f16\u7801\u7684\u5185\u5bb9\nqr.make(fit=True)\n\n# \u751f\u6210\u4e8c\u7ef4\u7801\u56fe\u50cf\nimg = qr.make_image(fill_color=&quot;black&quot;, back_color=&quot;white&quot;)\nimg.save(&#39;qrcode.png&#39;)  # \u4fdd\u5b58\u4e3aPNG\u6587\u4ef6\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u751f\u6210\u4e00\u4e2a\u540d\u4e3a<code>qrcode.png<\/code>\u7684\u4e8c\u7ef4\u7801\u6587\u4ef6\u3002<\/p>\n<p><strong>\u751f\u6210\u7684\u4e8c\u7ef4\u7801\u53ef\u4ee5\u5305\u542b\u54ea\u4e9b\u7c7b\u578b\u7684\u4fe1\u606f\uff1f<\/strong><br \/>\u4e8c\u7ef4\u7801\u53ef\u4ee5\u5b58\u50a8\u591a\u79cd\u7c7b\u578b\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u7f51\u5740\u3001\u6587\u672c\u3001\u7535\u8bdd\u53f7\u7801\u3001\u7535\u5b50\u90ae\u4ef6\u5730\u5740\u7b49\u3002\u7528\u6237\u53ef\u4ee5\u6839\u636e\u5b9e\u9645\u9700\u6c42\u9009\u62e9\u8981\u7f16\u7801\u7684\u5185\u5bb9\u3002\u4f8b\u5982\uff0c\u82e5\u5e0c\u671b\u5206\u4eab\u4e00\u4e2a\u7f51\u7ad9\u94fe\u63a5\uff0c\u53ef\u4ee5\u76f4\u63a5\u5c06\u7f51\u5740\u6dfb\u52a0\u5230\u4e8c\u7ef4\u7801\u4e2d\u3002<\/p>\n<p><strong>\u5982\u4f55\u81ea\u5b9a\u4e49\u4e8c\u7ef4\u7801\u7684\u5916\u89c2\uff1f<\/strong><br \/>\u4f7f\u7528<code>qrcode<\/code>\u5e93\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e<code>fill_color<\/code>\u548c<code>back_color<\/code>\u53c2\u6570\u6765\u6539\u53d8\u4e8c\u7ef4\u7801\u7684\u989c\u8272\u3002\u6b64\u5916\uff0c\u53ef\u4ee5\u4f7f\u7528<code>version<\/code>\u53c2\u6570\u8c03\u6574\u4e8c\u7ef4\u7801\u7684\u590d\u6742\u7a0b\u5ea6\u3002\u66f4\u9ad8\u7ea7\u7684\u81ea\u5b9a\u4e49\u53ef\u4ee5\u901a\u8fc7\u56fe\u50cf\u5904\u7406\u5e93\uff08\u5982PIL\uff09\u5bf9\u751f\u6210\u7684\u4e8c\u7ef4\u7801\u56fe\u50cf\u8fdb\u884c\u4fee\u6539\uff0c\u4ee5\u6dfb\u52a0logo\u6216\u66f4\u6539\u56fe\u6848\u3002<\/p>\n<p><strong>\u4e8c\u7ef4\u7801\u7684\u626b\u63cf\u9700\u6c42\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u4e3a\u4e86\u626b\u63cf\u4e8c\u7ef4\u7801\uff0c\u7528\u6237\u9700\u8981\u4e00\u4e2a\u914d\u5907\u6444\u50cf\u5934\u7684\u8bbe\u5907\uff0c\u5982\u667a\u80fd\u624b\u673a\u6216\u5e73\u677f\u7535\u8111\u3002\u5927\u591a\u6570\u73b0\u4ee3\u624b\u673a\u90fd\u5185\u7f6e\u4e8c\u7ef4\u7801\u626b\u63cf\u529f\u80fd\uff0c\u7528\u6237\u53ea\u9700\u6253\u5f00\u76f8\u673a\u5e76\u5bf9\u51c6\u4e8c\u7ef4\u7801\uff0c\u7cfb\u7edf\u4f1a\u81ea\u52a8\u8bc6\u522b\u5e76\u663e\u793a\u76f8\u5173\u4fe1\u606f\u3002\u786e\u4fdd\u4e8c\u7ef4\u7801\u6e05\u6670\u4e14\u6ca1\u6709\u635f\u574f\uff0c\u4ee5\u63d0\u9ad8\u626b\u63cf\u6210\u529f\u7387\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u4ee3\u7801\u5982\u4f55\u505a\u6210\u4e8c\u7ef4\u7801 \u751f\u6210\u4e8c\u7ef4\u7801\u7684\u6b65\u9aa4\u6709\uff1a\u9009\u62e9\u5408\u9002\u7684\u5e93\u3001\u7f16\u5199\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u4ee3\u7801\u3001\u4fdd\u5b58\u548c\u5c55\u793a\u4e8c\u7ef4\u7801\u3001\u4f18\u5316 [&hellip;]","protected":false},"author":3,"featured_media":1126839,"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\/1126827"}],"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=1126827"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1126827\/revisions"}],"predecessor-version":[{"id":1126842,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1126827\/revisions\/1126842"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1126839"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1126827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1126827"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1126827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}