{"id":985706,"date":"2024-12-27T07:38:54","date_gmt":"2024-12-26T23:38:54","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/985706.html"},"modified":"2024-12-27T07:38:57","modified_gmt":"2024-12-26T23:38:57","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8python%e5%ae%89%e8%a3%85pil","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/985706.html","title":{"rendered":"\u5982\u4f55\u5728python\u5b89\u88c5pil"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24212742\/5a403ea6-abe1-4fc4-8ee7-a2d3c80e16ab.webp\" alt=\"\u5982\u4f55\u5728python\u5b89\u88c5pil\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u5b89\u88c5PIL\u7684\u6838\u5fc3\u6b65\u9aa4\u5305\u62ec\uff1a\u4f7f\u7528pip\u5b89\u88c5\u3001\u786e\u4fddPython\u7248\u672c\u517c\u5bb9\u3001\u4f7f\u7528\u56fe\u50cf\u5e93Pillow\u66ff\u4ee3PIL\u3002<\/strong>Pillow\u662fPIL\uff08Python Imaging Library\uff09\u7684\u4e00\u4e2a\u5206\u652f\uff0c\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u7279\u6027\u548c\u6301\u7eed\u7684\u66f4\u65b0\uff0c\u56e0\u6b64\u88ab\u5e7f\u6cdb\u63a8\u8350\u4f7f\u7528\u3002\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u7684Python\u7248\u672c\u662f3.x\uff0c\u56e0\u4e3aPillow\u5bf9Python 2\u7684\u652f\u6301\u6709\u9650\u3002\u7136\u540e\uff0c\u6253\u5f00\u547d\u4ee4\u884c\u754c\u9762\uff0c\u4f7f\u7528pip\u5b89\u88c5Pillow\u5e93\uff1a<code>pip install Pillow<\/code>\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7<code>from PIL import Image<\/code>\u6765\u5bfc\u5165\u5e76\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u7684\u6b65\u9aa4\u548c\u4e00\u4e9b\u5e38\u89c1\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001PIL\u4e0ePillow\u7684\u533a\u522b<\/p>\n<\/p>\n<p><p>PIL\uff08Python Imaging Library\uff09\u662f\u4e00\u4e2a\u7528\u4e8e\u56fe\u50cf\u5904\u7406\u7684\u5e93\uff0c\u4f46\u5b83\u5df2\u7ecf\u4e0d\u518d\u7ef4\u62a4\u3002Pillow\u662fPIL\u7684\u4e00\u4e2a\u517c\u5bb9\u5e93\uff0c\u63d0\u4f9b\u4e86\u5bf9PIL\u7684\u66ff\u4ee3\uff0c\u5e76\u4e14\u589e\u52a0\u4e86\u4e00\u4e9b\u65b0\u7684\u7279\u6027\u548c\u6301\u7eed\u7684\u66f4\u65b0\u3002\u56e0\u6b64\uff0c\u901a\u5e38\u5efa\u8bae\u5728\u73b0\u4ee3Python\u9879\u76ee\u4e2d\u4f7f\u7528Pillow\u800c\u4e0d\u662fPIL\u3002<\/p>\n<\/p>\n<p><p>Pillow\u4e0d\u4ec5\u652f\u6301PIL\u7684\u6240\u6709\u529f\u80fd\uff0c\u8fd8\u589e\u52a0\u4e86\u5bf9\u66f4\u591a\u56fe\u50cf\u683c\u5f0f\u7684\u652f\u6301\u3001\u6539\u8fdb\u7684\u6027\u80fd\u548c\u66f4\u597d\u7684\u9519\u8bef\u5904\u7406\u3002\u6b64\u5916\uff0cPillow\u4fdd\u6301\u4e86\u4e0ePIL\u7684API\u517c\u5bb9\u6027\uff0c\u8fd9\u610f\u5473\u7740\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u76f4\u63a5\u66ff\u6362PIL\u800c\u65e0\u9700\u66f4\u6539\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528pip\u5b89\u88c5Pillow<\/p>\n<\/p>\n<p><p>\u8981\u5728Python\u73af\u5883\u4e2d\u5b89\u88c5Pillow\uff0c\u53ef\u4ee5\u4f7f\u7528pip\uff0c\u8fd9\u662fPython\u7684\u5305\u7ba1\u7406\u5668\u3002\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u548cpip\uff0c\u7136\u540e\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Pillow\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">pip install Pillow<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u4ecePython Package Index (PyPI)\u4e0b\u8f7d\u5e76\u5b89\u88c5Pillow\u7684\u6700\u65b0\u7248\u672c\u3002\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0cpip\u4f1a\u81ea\u52a8\u5904\u7406\u4f9d\u8d56\u5173\u7cfb\uff0c\u5e76\u786e\u4fddPillow\u5728\u4f60\u7684\u7cfb\u7edf\u4e0a\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u9a8c\u8bc1Pillow\u5b89\u88c5<\/p>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684Python\u811a\u672c\u6765\u9a8c\u8bc1Pillow\u662f\u5426\u5b89\u88c5\u6210\u529f\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>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>img = Image.new(&#39;RGB&#39;, (100, 100), color=&#39;red&#39;)<\/p>\n<h2><strong>\u4fdd\u5b58\u56fe\u50cf<\/strong><\/h2>\n<p>img.save(&#39;test_image.png&#39;)<\/p>\n<p>print(&quot;Pillow successfully installed and image created!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\uff0c\u5982\u679c\u6ca1\u6709\u62a5\u9519\uff0c\u5e76\u4e14\u5728\u4f60\u7684\u5f53\u524d\u76ee\u5f55\u4e0b\u751f\u6210\u4e86\u4e00\u4e2a\u540d\u4e3a<code>test_image.png<\/code>\u7684\u7ea2\u8272\u56fe\u50cf\u6587\u4ef6\uff0c\u5219\u8868\u793aPillow\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u5e38\u89c1\u95ee\u9898\u53ca\u89e3\u51b3\u65b9\u6848<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5\u5931\u8d25\u6216\u627e\u4e0d\u5230PIL<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>Pillow\u66ff\u4ee3\u4e86PIL\uff0c\u56e0\u6b64\u4f60\u9700\u8981\u786e\u4fdd\u5b89\u88c5\u7684\u662fPillow\u800c\u4e0d\u662fPIL\u3002\u5982\u679c\u4f60\u5c1d\u8bd5<code>pip install PIL<\/code>\uff0c\u4f1a\u62a5\u9519\uff0c\u56e0\u4e3aPIL\u5df2\u7ecf\u4e0d\u518d\u7ef4\u62a4\u3002<\/li>\n<li>\u5982\u679c\u4f7f\u7528<code>pip install Pillow<\/code>\u5b89\u88c5\u5931\u8d25\uff0c\u8bf7\u68c0\u67e5\u4f60\u7684\u7f51\u7edc\u8fde\u63a5\uff0c\u6216\u8005\u5c1d\u8bd5\u4f7f\u7528\u955c\u50cf\u6e90\uff08\u4f8b\u5982\u963f\u91cc\u4e91\u6216\u8c46\u74e3\uff09\u6765\u52a0\u901f\u4e0b\u8f7d\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u7248\u672c\u517c\u5bb9\u6027\u95ee\u9898<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u786e\u4fdd\u4f60\u7684Python\u7248\u672c\u57283.x\u4ee5\u4e0a\uff0c\u56e0\u4e3aPillow\u7684\u6700\u65b0\u7248\u672c\u4e0d\u518d\u652f\u6301Python 2\u3002<\/li>\n<li>\u5982\u679c\u9700\u8981\u4f7f\u7528\u65e7\u7248\u672c\u7684Pillow\u4ee5\u517c\u5bb9\u65e7\u7684Python\u9879\u76ee\uff0c\u53ef\u4ee5\u6307\u5b9a\u7248\u672c\u53f7\u8fdb\u884c\u5b89\u88c5\uff0c\u4f8b\u5982\uff1a<code>pip install Pillow==6.2.0<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u56fe\u50cf\u5e93\u4f9d\u8d56\u95ee\u9898<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>Pillow\u53ef\u80fd\u9700\u8981\u4e00\u4e9b\u7cfb\u7edf\u7ea7\u7684\u5e93\uff0c\u5982libjpeg\u3001zlib\u7b49\u3002\u5728Linux\u7cfb\u7edf\u4e0a\uff0c\u786e\u4fdd\u8fd9\u4e9b\u5e93\u5df2\u7ecf\u5b89\u88c5\u3002\u4f8b\u5982\uff0c\u5728Ubuntu\u4e0a\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<code>sudo apt-get install libjpeg-dev zlib1g-dev<\/code>\u6765\u5b89\u88c5\u8fd9\u4e9b\u4f9d\u8d56\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u5728\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u7684\u5b89\u88c5\u6ce8\u610f\u4e8b\u9879<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Windows<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>Pillow\u7684\u5b89\u88c5\u901a\u5e38\u4e0d\u9700\u8981\u989d\u5916\u914d\u7f6e\uff0c\u56e0\u4e3a\u5b83\u4f1a\u81ea\u52a8\u5904\u7406\u4f9d\u8d56\u5173\u7cfb\u3002\u4f46\u786e\u4fdd\u4f60\u7684Python\u548cpip\u5df2\u6b63\u786e\u914d\u7f6e\u5728\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u4e2d\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>macOS<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728macOS\u4e0a\uff0cHomebrew\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u5e2e\u52a9\u5b89\u88c5\u4e00\u4e9bPillow\u53ef\u80fd\u9700\u8981\u7684\u4f9d\u8d56\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>brew install libjpeg<\/code>\u6765\u5b89\u88c5JPEG\u652f\u6301\u5e93\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Linux<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728Linux\u4e0a\uff0c\u7279\u522b\u662fDebian\u7cfb\u7684\u53d1\u884c\u7248\uff0c\u53ef\u80fd\u9700\u8981\u624b\u52a8\u5b89\u88c5\u4e00\u4e9b\u4f9d\u8d56\u5e93\u3002\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177\u5982apt\u6216yum\u6765\u5b89\u88c5\u9700\u8981\u7684\u4f9d\u8d56\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u516d\u3001Pillow\u7684\u57fa\u672c\u4f7f\u7528\u793a\u4f8b<\/p>\n<\/p>\n<p><p>Pillow\u63d0\u4f9b\u4e86\u8bb8\u591a\u5f3a\u5927\u7684\u56fe\u50cf\u5904\u7406\u529f\u80fd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u57fa\u672c\u7684\u4f7f\u7528\u793a\u4f8b\uff0c\u5e2e\u52a9\u4f60\u5feb\u901f\u4e0a\u624bPillow\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u6253\u5f00\u548c\u663e\u793a\u56fe\u50cf<\/strong>\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u6253\u5f00\u56fe\u50cf<\/strong><\/h2>\n<p>img = Image.open(&#39;example.jpg&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>img.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u56fe\u50cf\u8f6c\u6362\u548c\u4fdd\u5b58<\/strong>\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\"># \u8f6c\u6362\u56fe\u50cf\u6a21\u5f0f<\/p>\n<p>img_gray = img.convert(&#39;L&#39;)<\/p>\n<h2><strong>\u4fdd\u5b58\u56fe\u50cf<\/strong><\/h2>\n<p>img_gray.save(&#39;example_gray.jpg&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u56fe\u50cf\u7f29\u653e\u548c\u88c1\u526a<\/strong>\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\"># \u7f29\u653e\u56fe\u50cf<\/p>\n<p>img_resized = img.resize((200, 200))<\/p>\n<h2><strong>\u88c1\u526a\u56fe\u50cf<\/strong><\/h2>\n<p>img_cropped = img.crop((50, 50, 150, 150))<\/p>\n<h2><strong>\u4fdd\u5b58\u88c1\u526a\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>img_cropped.save(&#39;example_cropped.jpg&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li><strong>\u6dfb\u52a0\u6587\u672c\u6c34\u5370<\/strong>\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">from PIL import ImageDraw, ImageFont<\/p>\n<h2><strong>\u521b\u5efa\u7ed8\u56fe\u5bf9\u8c61<\/strong><\/h2>\n<p>draw = ImageDraw.Draw(img)<\/p>\n<h2><strong>\u8bbe\u7f6e\u5b57\u4f53<\/strong><\/h2>\n<p>font = ImageFont.truetype(&quot;arial.ttf&quot;, 36)<\/p>\n<h2><strong>\u6dfb\u52a0\u6587\u672c<\/strong><\/h2>\n<p>draw.text((10, 10), &quot;Sample Watermark&quot;, font=font, fill=(255, 255, 255))<\/p>\n<h2><strong>\u4fdd\u5b58\u5e26\u6709\u6c34\u5370\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>img.save(&#39;example_watermarked.jpg&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e03\u3001Pillow\u7684\u9ad8\u7ea7\u529f\u80fd<\/p>\n<\/p>\n<p><p>Pillow\u4e0d\u4ec5\u652f\u6301\u57fa\u672c\u7684\u56fe\u50cf\u5904\u7406\uff0c\u8fd8\u63d0\u4f9b\u4e86\u4e00\u4e9b\u9ad8\u7ea7\u529f\u80fd\uff0c\u5982\u56fe\u50cf\u6ee4\u955c\u3001\u56fe\u50cf\u589e\u5f3a\u3001\u56fe\u50cf\u5408\u5e76\u7b49\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5e94\u7528\u6ee4\u955c<\/strong>\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">from PIL import ImageFilter<\/p>\n<h2><strong>\u5e94\u7528\u6a21\u7cca\u6ee4\u955c<\/strong><\/h2>\n<p>img_blur = img.filter(ImageFilter.BLUR)<\/p>\n<h2><strong>\u4fdd\u5b58\u6a21\u7cca\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>img_blur.save(&#39;example_blur.jpg&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u56fe\u50cf\u589e\u5f3a<\/strong>\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">from PIL import ImageEnhance<\/p>\n<h2><strong>\u589e\u5f3a\u56fe\u50cf\u5bf9\u6bd4\u5ea6<\/strong><\/h2>\n<p>enhancer = ImageEnhance.Contrast(img)<\/p>\n<p>img_contrast = enhancer.enhance(2.0)<\/p>\n<h2><strong>\u4fdd\u5b58\u589e\u5f3a\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>img_contrast.save(&#39;example_contrast.jpg&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u56fe\u50cf\u5408\u5e76<\/strong>\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u56fe\u50cf\u7528\u4e8e\u5408\u5e76<\/p>\n<p>img_merge = Image.new(&#39;RGB&#39;, (400, 400))<\/p>\n<h2><strong>\u7c98\u8d34\u56fe\u50cf<\/strong><\/h2>\n<p>img_merge.paste(img_resized, (0, 0))<\/p>\n<p>img_merge.paste(img_cropped, (200, 0))<\/p>\n<h2><strong>\u4fdd\u5b58\u5408\u5e76\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>img_merge.save(&#39;example_merged.jpg&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u516b\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>Pillow\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u56fe\u50cf\u5904\u7406\u5e93\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u548c\u826f\u597d\u7684\u517c\u5bb9\u6027\u3002\u901a\u8fc7\u4e86\u89e3Pillow\u7684\u5b89\u88c5\u3001\u57fa\u672c\u4f7f\u7528\u548c\u9ad8\u7ea7\u529f\u80fd\uff0c\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5728Python\u9879\u76ee\u4e2d\u66f4\u9ad8\u6548\u5730\u8fdb\u884c\u56fe\u50cf\u5904\u7406\u3002\u65e0\u8bba\u662f\u7b80\u5355\u7684\u56fe\u50cf\u7f29\u653e\u3001\u88c1\u526a\uff0c\u8fd8\u662f\u590d\u6742\u7684\u56fe\u50cf\u6ee4\u955c\u548c\u589e\u5f3a\uff0cPillow\u90fd\u80fd\u63d0\u4f9b\u4fbf\u6377\u7684\u89e3\u51b3\u65b9\u6848\u3002\u901a\u8fc7\u4e0d\u65ad\u5b9e\u8df5\u548c\u63a2\u7d22\uff0c\u4f60\u5c06\u80fd\u591f\u5145\u5206\u53d1\u6325Pillow\u7684\u6f5c\u529b\uff0c\u4e3a\u4f60\u7684\u9879\u76ee\u589e\u6dfb\u66f4\u591a\u7684\u56fe\u50cf\u5904\u7406\u80fd\u529b\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5b89\u88c5PIL\u5e93\uff1f<\/strong><br \/>PIL\uff08Python Imaging Library\uff09\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u56fe\u50cf\u5904\u7406\u5e93\u3002\u8981\u5728Python\u4e2d\u5b89\u88c5PIL\uff0c\u53ef\u4ee5\u901a\u8fc7pip\u547d\u4ee4\u6765\u5b89\u88c5Pillow\uff0c\u8fd9\u662fPIL\u7684\u4e00\u4e2a\u5206\u652f\u548c\u66ff\u4ee3\u54c1\uff0c\u529f\u80fd\u66f4\u4e3a\u5f3a\u5927\u4e14\u66f4\u65b0\u7ef4\u62a4\u66f4\u4e3a\u9891\u7e41\u3002\u6253\u5f00\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u8f93\u5165<code>pip install Pillow<\/code>\u5373\u53ef\u5b8c\u6210\u5b89\u88c5\u3002<\/p>\n<p><strong>Pillow\u548cPIL\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/strong><br \/>Pillow\u662fPIL\u7684\u4e00\u4e2a\u53cb\u597d\u5206\u652f\uff0c\u63d0\u4f9b\u4e86\u5bf9Python 3\u7684\u652f\u6301\uff0c\u4fee\u590d\u4e86\u8bb8\u591aPIL\u4e2d\u7684bug\uff0c\u5e76\u6dfb\u52a0\u4e86\u8bb8\u591a\u65b0\u529f\u80fd\u3002\u56e0\u6b64\uff0c\u5efa\u8bae\u4f7f\u7528Pillow\u800c\u4e0d\u662fPIL\uff0c\u7279\u522b\u662f\u5982\u679c\u60a8\u6b63\u5728\u4f7f\u7528\u6700\u65b0\u7248\u672c\u7684Python\u3002<\/p>\n<p><strong>\u5b89\u88c5Pillow\u540e\uff0c\u5982\u4f55\u9a8c\u8bc1\u5176\u662f\u5426\u6210\u529f\uff1f<\/strong><br \/>\u5728Python\u73af\u5883\u4e2d\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u5c1d\u8bd5\u5bfc\u5165Pillow\u6765\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f\u3002\u5728\u547d\u4ee4\u884c\u6216Python\u89e3\u91ca\u5668\u4e2d\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801\uff1a  <\/p>\n<pre><code class=\"language-python\">from PIL import Image\nprint(&quot;Pillow\u5b89\u88c5\u6210\u529f\uff01&quot;)\n<\/code><\/pre>\n<p>\u5982\u679c\u6ca1\u6709\u9519\u8bef\u4fe1\u606f\u51fa\u73b0\uff0c\u90a3\u4e48\u60a8\u5c31\u6210\u529f\u5b89\u88c5\u4e86Pillow\u3002<\/p>\n<p><strong>Pillow\u652f\u6301\u54ea\u4e9b\u56fe\u50cf\u683c\u5f0f\uff1f<\/strong><br \/>Pillow\u652f\u6301\u591a\u79cd\u56fe\u50cf\u683c\u5f0f\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8eJPEG\u3001PNG\u3001BMP\u3001GIF\u3001TIFF\u7b49\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528Pillow\u5904\u7406\u8fd9\u4e9b\u683c\u5f0f\u7684\u56fe\u50cf\u8fdb\u884c\u6253\u5f00\u3001\u7f16\u8f91\u548c\u4fdd\u5b58\u64cd\u4f5c\uff0c\u975e\u5e38\u65b9\u4fbf\u3002<\/p>\n<p><strong>\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u9047\u5230\u95ee\u9898\u8be5\u600e\u4e48\u529e\uff1f<\/strong><br \/>\u5982\u679c\u5728\u5b89\u88c5Pillow\u65f6\u9047\u5230\u95ee\u9898\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u66f4\u65b0pip\u5230\u6700\u65b0\u7248\u672c\uff0c\u4f7f\u7528\u547d\u4ee4<code>pip install --upgrade pip<\/code>\u3002\u540c\u65f6\uff0c\u786e\u4fdd\u60a8\u7684Python\u7248\u672c\u4e0ePillow\u517c\u5bb9\uff0c\u60a8\u53ef\u4ee5\u8bbf\u95eePillow\u7684\u5b98\u65b9\u6587\u6863\u83b7\u53d6\u66f4\u591a\u5e2e\u52a9\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u5b89\u88c5PIL\u7684\u6838\u5fc3\u6b65\u9aa4\u5305\u62ec\uff1a\u4f7f\u7528pip\u5b89\u88c5\u3001\u786e\u4fddPython\u7248\u672c\u517c\u5bb9\u3001\u4f7f\u7528\u56fe\u50cf\u5e93Pillow\u66ff\u4ee3 [&hellip;]","protected":false},"author":3,"featured_media":985713,"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\/985706"}],"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=985706"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/985706\/revisions"}],"predecessor-version":[{"id":985716,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/985706\/revisions\/985716"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/985713"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=985706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=985706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=985706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}