{"id":1012488,"date":"2024-12-27T11:39:25","date_gmt":"2024-12-27T03:39:25","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1012488.html"},"modified":"2024-12-27T11:39:29","modified_gmt":"2024-12-27T03:39:29","slug":"python%e5%a6%82%e4%bd%95%e6%b7%bb%e5%8a%a0%e5%9b%be%e7%89%87%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1012488.html","title":{"rendered":"python\u5982\u4f55\u6dfb\u52a0\u56fe\u7247\u6559\u7a0b"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25090246\/daec9add-ba90-44ce-8bde-5c024d0cf5df.webp\" alt=\"python\u5982\u4f55\u6dfb\u52a0\u56fe\u7247\u6559\u7a0b\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u6dfb\u52a0\u56fe\u7247\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\uff0c\u5982\u4f7f\u7528PIL\u3001OpenCV\u6216Matplotlib\u5e93\u3002PIL\u548cOpenCV\u9002\u5408\u8fdb\u884c\u56fe\u50cf\u5904\u7406\u548c\u7f16\u8f91\uff0cMatplotlib\u5219\u9002\u5408\u7528\u4e8e\u6570\u636e\u53ef\u89c6\u5316\u3002\u672c\u6587\u5c06\u4e3b\u8981\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u5e93\u5728Python\u4e2d\u6dfb\u52a0\u548c\u663e\u793a\u56fe\u7247\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528PIL(Pillow)\u5e93<\/p>\n<\/p>\n<p><p>PIL\uff08Python Imaging Library\uff09\u662fPython\u4e2d\u4e00\u4e2a\u5f3a\u5927\u7684\u56fe\u50cf\u5904\u7406\u5e93\u3002Pillow\u662fPIL\u7684\u4e00\u4e2a\u5206\u652f\uff0c\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u529f\u80fd\u548c\u652f\u6301\u3002\u8981\u4f7f\u7528Pillow\u5e93\uff0c\u9996\u5148\u9700\u8981\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<ol>\n<li><strong>\u52a0\u8f7d\u548c\u663e\u793a\u56fe\u7247<\/strong><\/li>\n<\/ol>\n<p><p>\u8981\u5728Python\u4e2d\u52a0\u8f7d\u548c\u663e\u793a\u56fe\u7247\uff0c\u53ef\u4ee5\u4f7f\u7528Pillow\u5e93\u4e2d\u7684<code>Image<\/code>\u6a21\u5757\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u6253\u5f00\u56fe\u50cf\u6587\u4ef6<\/strong><\/h2>\n<p>image = Image.open(&#39;example.jpg&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>Image.open()<\/code>\u51fd\u6570\u7528\u4e8e\u6253\u5f00\u56fe\u50cf\u6587\u4ef6\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2aImage\u5bf9\u8c61\u3002<code>image.show()<\/code>\u65b9\u6cd5\u7528\u4e8e\u5728\u9ed8\u8ba4\u56fe\u50cf\u67e5\u770b\u5668\u4e2d\u663e\u793a\u56fe\u50cf\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5728\u56fe\u7247\u4e0a\u6dfb\u52a0\u6587\u5b57<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u56fe\u50cf\u4e0a\u6dfb\u52a0\u6587\u5b57\u53ef\u4ee5\u4f7f\u7528Pillow\u7684<code>ImageDraw<\/code>\u6a21\u5757\u3002\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u5728\u56fe\u50cf\u4e0a\u6dfb\u52a0\u6587\u5b57\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image, ImageDraw, ImageFont<\/p>\n<h2><strong>\u6253\u5f00\u56fe\u50cf\u6587\u4ef6<\/strong><\/h2>\n<p>image = Image.open(&#39;example.jpg&#39;)<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u53ef\u7528\u4e8e\u7ed8\u56fe\u7684\u5bf9\u8c61<\/strong><\/h2>\n<p>draw = ImageDraw.Draw(image)<\/p>\n<h2><strong>\u5b9a\u4e49\u5b57\u4f53\u548c\u5927\u5c0f<\/strong><\/h2>\n<p>font = ImageFont.truetype(&#39;arial.ttf&#39;, 36)<\/p>\n<h2><strong>\u6dfb\u52a0\u6587\u5b57<\/strong><\/h2>\n<p>draw.text((10, 10), &quot;Hello, World!&quot;, font=font, fill=&#39;white&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>ImageDraw.Draw()<\/code>\u51fd\u6570\u7528\u4e8e\u521b\u5efa\u4e00\u4e2a\u7528\u4e8e\u7ed8\u56fe\u7684\u5bf9\u8c61\uff0c<code>draw.text()<\/code>\u65b9\u6cd5\u7528\u4e8e\u5728\u56fe\u50cf\u4e0a\u6dfb\u52a0\u6587\u5b57\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528OpenCV\u5e93<\/p>\n<\/p>\n<p><p>OpenCV\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u8ba1\u7b97\u673a\u89c6\u89c9\u5e93\uff0c\u9002\u5408\u8fdb\u884c\u66f4\u590d\u6742\u7684\u56fe\u50cf\u5904\u7406\u4efb\u52a1\u3002\u8981\u4f7f\u7528OpenCV\u5e93\uff0c\u540c\u6837\u9700\u8981\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install opencv-python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol>\n<li><strong>\u52a0\u8f7d\u548c\u663e\u793a\u56fe\u7247<\/strong><\/li>\n<\/ol>\n<p><p>\u4f7f\u7528OpenCV\u52a0\u8f7d\u548c\u663e\u793a\u56fe\u7247\u975e\u5e38\u7b80\u5355\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<h2><strong>\u8bfb\u53d6\u56fe\u50cf<\/strong><\/h2>\n<p>image = cv2.imread(&#39;example.jpg&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>cv2.imshow(&#39;Image&#39;, image)<\/p>\n<h2><strong>\u7b49\u5f85\u6309\u952e\u4e8b\u4ef6\uff0c\u7136\u540e\u5173\u95ed\u7a97\u53e3<\/strong><\/h2>\n<p>cv2.w<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>tKey(0)<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>cv2.imread()<\/code>\u51fd\u6570\u7528\u4e8e\u8bfb\u53d6\u56fe\u50cf\u6587\u4ef6\uff0c<code>cv2.imshow()<\/code>\u51fd\u6570\u7528\u4e8e\u5728\u7a97\u53e3\u4e2d\u663e\u793a\u56fe\u50cf\uff0c<code>cv2.waitKey(0)<\/code>\u4f7f\u7a97\u53e3\u4fdd\u6301\u6253\u5f00\u72b6\u6001\u76f4\u5230\u7528\u6237\u6309\u4e0b\u952e\uff0c<code>cv2.destroyAllWindows()<\/code>\u7528\u4e8e\u5173\u95ed\u7a97\u53e3\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5728\u56fe\u7247\u4e0a\u6dfb\u52a0\u6587\u5b57<\/strong><\/li>\n<\/ol>\n<p><p>OpenCV\u4e5f\u63d0\u4f9b\u4e86\u5728\u56fe\u50cf\u4e0a\u6dfb\u52a0\u6587\u5b57\u7684\u529f\u80fd\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<h2><strong>\u8bfb\u53d6\u56fe\u50cf<\/strong><\/h2>\n<p>image = cv2.imread(&#39;example.jpg&#39;)<\/p>\n<h2><strong>\u6dfb\u52a0\u6587\u5b57<\/strong><\/h2>\n<p>font = cv2.FONT_HERSHEY_SIMPLEX<\/p>\n<p>cv2.putText(image, &#39;Hello, World!&#39;, (10, 500), font, 4, (255, 255, 255), 2, cv2.LINE_AA)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>cv2.imshow(&#39;Image with Text&#39;, image)<\/p>\n<p>cv2.waitKey(0)<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>cv2.putText()<\/code>\u51fd\u6570\u7528\u4e8e\u5728\u56fe\u50cf\u4e0a\u6dfb\u52a0\u6587\u5b57\uff0c\u63a5\u53d7\u591a\u4e2a\u53c2\u6570\uff0c\u5305\u62ec\u6587\u672c\u5185\u5bb9\u3001\u4f4d\u7f6e\u3001\u5b57\u4f53\u3001\u5927\u5c0f\u3001\u989c\u8272\u7b49\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528Matplotlib\u5e93<\/p>\n<\/p>\n<p><p>Matplotlib\u662f\u4e00\u4e2a\u7528\u4e8e\u6570\u636e\u53ef\u89c6\u5316\u7684\u5e93\uff0c\u867d\u7136\u4e0d\u4e13\u7528\u4e8e\u56fe\u50cf\u5904\u7406\uff0c\u4f46\u4e5f\u53ef\u4ee5\u7528\u4e8e\u52a0\u8f7d\u548c\u663e\u793a\u56fe\u50cf\u3002\u9996\u5148\u9700\u8981\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install matplotlib<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol>\n<li><strong>\u52a0\u8f7d\u548c\u663e\u793a\u56fe\u7247<\/strong><\/li>\n<\/ol>\n<p><p>\u4f7f\u7528Matplotlib\u53ef\u4ee5\u8f7b\u677e\u5730\u52a0\u8f7d\u548c\u663e\u793a\u56fe\u7247\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import matplotlib.image as mpimg<\/p>\n<h2><strong>\u8bfb\u53d6\u56fe\u50cf<\/strong><\/h2>\n<p>image = mpimg.imread(&#39;example.jpg&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>plt.imshow(image)<\/p>\n<p>plt.axis(&#39;off&#39;)  # \u4e0d\u663e\u793a\u5750\u6807\u8f74<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>mpimg.imread()<\/code>\u51fd\u6570\u7528\u4e8e\u8bfb\u53d6\u56fe\u50cf\u6587\u4ef6\uff0c<code>plt.imshow()<\/code>\u51fd\u6570\u7528\u4e8e\u663e\u793a\u56fe\u50cf\uff0c<code>plt.axis(&#39;off&#39;)<\/code>\u7528\u4e8e\u9690\u85cf\u5750\u6807\u8f74\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5728\u56fe\u7247\u4e0a\u6dfb\u52a0\u6587\u5b57<\/strong><\/li>\n<\/ol>\n<p><p>\u53ef\u4ee5\u4f7f\u7528Matplotlib\u7684<code>text()<\/code>\u51fd\u6570\u5728\u56fe\u50cf\u4e0a\u6dfb\u52a0\u6587\u5b57\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import matplotlib.image as mpimg<\/p>\n<h2><strong>\u8bfb\u53d6\u56fe\u50cf<\/strong><\/h2>\n<p>image = mpimg.imread(&#39;example.jpg&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>plt.imshow(image)<\/p>\n<p>plt.axis(&#39;off&#39;)<\/p>\n<h2><strong>\u6dfb\u52a0\u6587\u5b57<\/strong><\/h2>\n<p>plt.text(10, 10, &#39;Hello, World!&#39;, color=&#39;white&#39;, fontsize=12)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>plt.text()<\/code>\u51fd\u6570\u7528\u4e8e\u5728\u56fe\u50cf\u4e0a\u6dfb\u52a0\u6587\u5b57\uff0c\u63a5\u53d7\u591a\u4e2a\u53c2\u6570\uff0c\u5305\u62ec\u6587\u672c\u5185\u5bb9\u3001\u4f4d\u7f6e\u3001\u989c\u8272\u548c\u5b57\u4f53\u5927\u5c0f\u7b49\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u4f7f\u7528\u5176\u4ed6\u5de5\u5177\u548c\u5e93<\/p>\n<\/p>\n<p><p>\u9664\u4e86\u4e0a\u8ff0\u4e09\u79cd\u5e38\u7528\u7684\u5e93\u5916\uff0c\u8fd8\u6709\u5176\u4ed6\u4e00\u4e9b\u5de5\u5177\u548c\u5e93\u53ef\u4ee5\u7528\u4e8e\u5728Python\u4e2d\u5904\u7406\u548c\u6dfb\u52a0\u56fe\u7247\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Scikit-image<\/strong>\uff1a\u4e00\u4e2a\u57fa\u4e8eSciPy\u7684\u56fe\u50cf\u5904\u7406\u5e93\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u56fe\u50cf\u5904\u7406\u529f\u80fd\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>ImageMagick<\/strong>\uff1a\u4e00\u4e2a\u5f3a\u5927\u7684\u56fe\u50cf\u5904\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u901a\u8fc7Python\u7684<code>Wand<\/code>\u5e93\u8fdb\u884c\u8c03\u7528\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Seaborn<\/strong>\uff1a\u57fa\u4e8eMatplotlib\u7684\u7edf\u8ba1\u6570\u636e\u53ef\u89c6\u5316\u5e93\uff0c\u53ef\u4ee5\u7528\u4e8e\u7ed8\u5236\u66f4\u52a0\u7f8e\u89c2\u7684\u56fe\u8868\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u6bcf\u79cd\u5e93\u548c\u5de5\u5177\u90fd\u6709\u5176\u4f18\u7f3a\u70b9\u548c\u9002\u7528\u573a\u666f\uff0c\u9009\u62e9\u9002\u5408\u81ea\u5df1\u9879\u76ee\u9700\u6c42\u7684\u5de5\u5177\u5c24\u4e3a\u91cd\u8981\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\u6dfb\u52a0\u56fe\u7247\u548c\u56fe\u50cf\u5904\u7406\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\u3002Pillow\u9002\u5408\u8fdb\u884c\u7b80\u5355\u7684\u56fe\u50cf\u5904\u7406\u548c\u7f16\u8f91\uff0cOpenCV\u9002\u5408\u5904\u7406\u590d\u6742\u7684\u8ba1\u7b97\u673a\u89c6\u89c9\u4efb\u52a1\uff0cMatplotlib\u9002\u5408\u6570\u636e\u53ef\u89c6\u5316\u3002\u9009\u62e9\u5408\u9002\u7684\u5e93\u53ef\u4ee5\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u3002\u6b64\u5916\uff0c\u6df1\u5165\u7406\u89e3\u6bcf\u4e2a\u5e93\u7684\u529f\u80fd\u548c\u4f7f\u7528\u573a\u666f\uff0c\u6709\u52a9\u4e8e\u5f00\u53d1\u8005\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u505a\u51fa\u66f4\u597d\u7684\u9009\u62e9\u548c\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5728Python\u4e2d\uff0c\u5982\u4f55\u4f7f\u7528PIL\u5e93\u6dfb\u52a0\u56fe\u7247\uff1f<\/strong><br \/>PIL\uff08Python Imaging Library\uff09\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u56fe\u50cf\u5904\u7406\u5e93\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u6253\u5f00\u3001\u64cd\u4f5c\u548c\u4fdd\u5b58\u56fe\u50cf\u3002\u8981\u5728Python\u4e2d\u6dfb\u52a0\u56fe\u7247\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5Pillow\u5e93\uff0c\u8fd9\u662fPIL\u7684\u4e00\u4e2a\u5206\u652f\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u793a\u4f8b\u52a0\u8f7d\u5e76\u663e\u793a\u4e00\u5f20\u56fe\u7247\uff1a  <\/p>\n<pre><code class=\"language-python\">from PIL import Image\n\n# \u6253\u5f00\u56fe\u7247\nimage = Image.open(&#39;your_image.jpg&#39;)\nimage.show()\n<\/code><\/pre>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u5728Python\u7a0b\u5e8f\u4e2d\u6dfb\u52a0\u548c\u5904\u7406\u56fe\u50cf\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u5c06\u591a\u5f20\u56fe\u7247\u5408\u5e76\u6210\u4e00\u5f20\uff1f<\/strong><br \/>\u5408\u5e76\u591a\u5f20\u56fe\u7247\u662f\u4e00\u9879\u5e38\u89c1\u9700\u6c42\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528Pillow\u5e93\u4e2d\u7684<code>paste<\/code>\u65b9\u6cd5\u6765\u5b9e\u73b0\u3002\u9996\u5148\uff0c\u786e\u4fdd\u6240\u6709\u56fe\u7247\u7684\u5c3a\u5bf8\u76f8\u540c\uff0c\u6216\u8005\u6839\u636e\u9700\u8981\u8c03\u6574\u5c3a\u5bf8\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u5c06\u4e24\u5f20\u56fe\u7247\u6c34\u5e73\u5408\u5e76\uff1a  <\/p>\n<pre><code class=\"language-python\">from PIL import Image\n\n# \u6253\u5f00\u4e24\u5f20\u56fe\u7247\nimage1 = Image.open(&#39;image1.jpg&#39;)\nimage2 = Image.open(&#39;image2.jpg&#39;)\n\n# \u521b\u5efa\u4e00\u4e2a\u65b0\u56fe\u50cf\uff0c\u7528\u4e8e\u5408\u5e76\nnew_image = Image.new(&#39;RGB&#39;, (image1.width + image2.width, image1.height))\n\n# \u7c98\u8d34\u4e24\u5f20\u56fe\u7247\nnew_image.paste(image1, (0, 0))\nnew_image.paste(image2, (image1.width, 0))\n\n# \u4fdd\u5b58\u5408\u5e76\u540e\u7684\u56fe\u7247\nnew_image.save(&#39;merged_image.jpg&#39;)\n<\/code><\/pre>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u591a\u5f20\u56fe\u7247\u5408\u5e76\u4e3a\u4e00\u5f20\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u4e3a\u56fe\u7247\u6dfb\u52a0\u6587\u5b57\u6c34\u5370\uff1f<\/strong><br \/>\u4e3a\u56fe\u7247\u6dfb\u52a0\u6587\u5b57\u6c34\u5370\u53ef\u4ee5\u4f7f\u7528Pillow\u5e93\u4e2d\u7684<code>ImageDraw<\/code>\u6a21\u5757\u3002\u60a8\u53ef\u4ee5\u9009\u62e9\u5b57\u4f53\u3001\u989c\u8272\u548c\u4f4d\u7f6e\uff0c\u5c06\u6587\u672c\u6dfb\u52a0\u5230\u56fe\u50cf\u4e0a\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a  <\/p>\n<pre><code class=\"language-python\">from PIL import Image, ImageDraw, ImageFont\n\n# \u6253\u5f00\u56fe\u7247\nimage = Image.open(&#39;your_image.jpg&#39;)\ndraw = ImageDraw.Draw(image)\n\n# \u8bbe\u7f6e\u5b57\u4f53\u548c\u4f4d\u7f6e\nfont = ImageFont.truetype(&#39;arial.ttf&#39;, 36)\ntext = &quot;Watermark&quot;\ntext_position = (10, 10)\n\n# \u6dfb\u52a0\u6587\u5b57\u6c34\u5370\ndraw.text(text_position, text, fill=(255, 255, 255), font=font)\n\n# \u4fdd\u5b58\u5e26\u6c34\u5370\u7684\u56fe\u7247\nimage.save(&#39;watermarked_image.jpg&#39;)\n<\/code><\/pre>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u60a8\u53ef\u4ee5\u4e3a\u60a8\u7684\u56fe\u7247\u6dfb\u52a0\u4e2a\u6027\u5316\u7684\u6587\u5b57\u6c34\u5370\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u6dfb\u52a0\u56fe\u7247\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\uff0c\u5982\u4f7f\u7528PIL\u3001OpenCV\u6216Matplotlib\u5e93\u3002PIL\u548cOp [&hellip;]","protected":false},"author":3,"featured_media":1012501,"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\/1012488"}],"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=1012488"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1012488\/revisions"}],"predecessor-version":[{"id":1012504,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1012488\/revisions\/1012504"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1012501"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1012488"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1012488"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1012488"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}