{"id":1051505,"date":"2024-12-31T14:16:59","date_gmt":"2024-12-31T06:16:59","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1051505.html"},"modified":"2024-12-31T14:17:02","modified_gmt":"2024-12-31T06:17:02","slug":"python3%e5%a6%82%e4%bd%95%e5%ae%89%e8%a3%85pil-image","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1051505.html","title":{"rendered":"python3\u5982\u4f55\u5b89\u88c5pil.image"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/5f24e584-6cd0-4bd4-9741-6849471d890e.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"python3\u5982\u4f55\u5b89\u88c5pil.image\" \/><\/p>\n<p><p> <strong>\u5728Python3\u4e2d\u5b89\u88c5PIL.Image\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/strong><\/p>\n<\/p>\n<p><p><strong>1\u3001\u4f7f\u7528pip\u5b89\u88c5Pillow\u5e93<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python3\u4e2d\uff0cPIL\uff08Python Imaging Library\uff09\u5df2\u7ecf\u88abPillow\u66ff\u4ee3\u3002Pillow\u662fPIL\u7684\u4e00\u4e2a\u5206\u652f\u5e76\u4e14\u517c\u5bb9PIL\u7684\u6240\u6709\u529f\u80fd\u3002\u8981\u5b89\u88c5Pillow\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">pip install Pillow<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>2\u3001\u5bfc\u5165PIL.Image\u6a21\u5757<\/strong><\/p>\n<\/p>\n<p><p>\u5b89\u88c5Pillow\u5e93\u540e\uff0c\u4f60\u53ef\u4ee5\u5bfc\u5165PIL.Image\u6a21\u5757\u6765\u4f7f\u7528\u56fe\u50cf\u5904\u7406\u529f\u80fd\u3002\u4e0b\u9762\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\u4e00\u4e2a\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><strong>\u8be6\u7ec6\u63cf\u8ff0Pillow\u5e93\u7684\u5b89\u88c5\u548c\u4f7f\u7528<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u5904\u7406\u56fe\u50cf\u65f6\uff0cPillow\u5e93\u662f\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u5de5\u5177\u3002\u5b83\u4e0d\u4ec5\u80fd\u591f\u6253\u5f00\u548c\u663e\u793a\u56fe\u50cf\uff0c\u8fd8\u652f\u6301\u56fe\u50cf\u7684\u5904\u7406\u548c\u8f6c\u6362\u3002\u4ee5\u4e0b\u662f\u5173\u4e8ePillow\u5e93\u7684\u4e00\u4e9b\u8be6\u7ec6\u63cf\u8ff0\u548c\u4f7f\u7528\u793a\u4f8b\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001Pillow\u5e93\u7684\u5b89\u88c5\u548c\u57fa\u672c\u4f7f\u7528<\/h2>\n<\/p>\n<p><h3>\u5b89\u88c5Pillow\u5e93<\/h3>\n<\/p>\n<p><p>\u8981\u5b89\u88c5Pillow\u5e93\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">pip install Pillow<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u5bfc\u5165PIL\u6a21\u5757\u6765\u4f7f\u7528Pillow\u5e93\u3002<\/p>\n<\/p>\n<p><h3>\u6253\u5f00\u548c\u663e\u793a\u56fe\u50cf<\/h3>\n<\/p>\n<p><p>Pillow\u5e93\u63d0\u4f9b\u4e86\u7b80\u5355\u7684\u65b9\u6cd5\u6765\u6253\u5f00\u548c\u663e\u793a\u56fe\u50cf\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u6253\u5f00\u4e00\u4e2a\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><h3>\u4fdd\u5b58\u56fe\u50cf<\/h3>\n<\/p>\n<p><p>Pillow\u5e93\u8fd8\u53ef\u4ee5\u5c06\u56fe\u50cf\u4fdd\u5b58\u4e3a\u4e0d\u540c\u7684\u683c\u5f0f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u6253\u5f00\u4e00\u4e2a\u56fe\u50cf\u6587\u4ef6<\/strong><\/h2>\n<p>image = Image.open(&#39;example.jpg&#39;)<\/p>\n<h2><strong>\u5c06\u56fe\u50cf\u4fdd\u5b58\u4e3aPNG\u683c\u5f0f<\/strong><\/h2>\n<p>image.save(&#39;example.png&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e8c\u3001\u56fe\u50cf\u5904\u7406\u548c\u8f6c\u6362<\/h2>\n<\/p>\n<p><h3>\u56fe\u50cf\u5927\u5c0f\u8c03\u6574<\/h3>\n<\/p>\n<p><p>Pillow\u5e93\u53ef\u4ee5\u65b9\u4fbf\u5730\u8c03\u6574\u56fe\u50cf\u7684\u5927\u5c0f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u6253\u5f00\u4e00\u4e2a\u56fe\u50cf\u6587\u4ef6<\/strong><\/h2>\n<p>image = Image.open(&#39;example.jpg&#39;)<\/p>\n<h2><strong>\u8c03\u6574\u56fe\u50cf\u5927\u5c0f<\/strong><\/h2>\n<p>resized_image = image.resize((200, 200))<\/p>\n<h2><strong>\u663e\u793a\u8c03\u6574\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>resized_image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56fe\u50cf\u526a\u88c1<\/h3>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u4f7f\u7528Pillow\u5e93\u526a\u88c1\u56fe\u50cf\u7684\u4e00\u90e8\u5206\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u6253\u5f00\u4e00\u4e2a\u56fe\u50cf\u6587\u4ef6<\/strong><\/h2>\n<p>image = Image.open(&#39;example.jpg&#39;)<\/p>\n<h2><strong>\u526a\u88c1\u56fe\u50cf<\/strong><\/h2>\n<p>cropped_image = image.crop((50, 50, 200, 200))<\/p>\n<h2><strong>\u663e\u793a\u526a\u88c1\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>cropped_image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56fe\u50cf\u65cb\u8f6c<\/h3>\n<\/p>\n<p><p>Pillow\u5e93\u8fd8\u53ef\u4ee5\u65cb\u8f6c\u56fe\u50cf\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u6253\u5f00\u4e00\u4e2a\u56fe\u50cf\u6587\u4ef6<\/strong><\/h2>\n<p>image = Image.open(&#39;example.jpg&#39;)<\/p>\n<h2><strong>\u65cb\u8f6c\u56fe\u50cf<\/strong><\/h2>\n<p>rotated_image = image.rotate(45)<\/p>\n<h2><strong>\u663e\u793a\u65cb\u8f6c\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>rotated_image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e09\u3001\u56fe\u50cf\u6ee4\u955c\u548c\u7279\u6548<\/h2>\n<\/p>\n<p><p>Pillow\u5e93\u63d0\u4f9b\u4e86\u4e00\u4e9b\u56fe\u50cf\u6ee4\u955c\u548c\u7279\u6548\uff0c\u53ef\u4ee5\u7528\u4e8e\u56fe\u50cf\u5904\u7406\u3002<\/p>\n<\/p>\n<p><h3>\u5e94\u7528\u6ee4\u955c<\/h3>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5e94\u7528\u6a21\u7cca\u6ee4\u955c\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image, ImageFilter<\/p>\n<h2><strong>\u6253\u5f00\u4e00\u4e2a\u56fe\u50cf\u6587\u4ef6<\/strong><\/h2>\n<p>image = Image.open(&#39;example.jpg&#39;)<\/p>\n<h2><strong>\u5e94\u7528\u6a21\u7cca\u6ee4\u955c<\/strong><\/h2>\n<p>blurred_image = image.filter(ImageFilter.BLUR)<\/p>\n<h2><strong>\u663e\u793a\u5e94\u7528\u6ee4\u955c\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>blurred_image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u8c03\u6574\u56fe\u50cf\u989c\u8272<\/h3>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u4f7f\u7528Pillow\u5e93\u8c03\u6574\u56fe\u50cf\u7684\u989c\u8272\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image, ImageEnhance<\/p>\n<h2><strong>\u6253\u5f00\u4e00\u4e2a\u56fe\u50cf\u6587\u4ef6<\/strong><\/h2>\n<p>image = Image.open(&#39;example.jpg&#39;)<\/p>\n<h2><strong>\u8c03\u6574\u56fe\u50cf\u7684\u5bf9\u6bd4\u5ea6<\/strong><\/h2>\n<p>enhancer = ImageEnhance.Contrast(image)<\/p>\n<p>enhanced_image = enhancer.enhance(2.0)<\/p>\n<h2><strong>\u663e\u793a\u8c03\u6574\u5bf9\u6bd4\u5ea6\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>enhanced_image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u56db\u3001\u56fe\u50cf\u683c\u5f0f\u8f6c\u6362\u548c\u6279\u91cf\u5904\u7406<\/h2>\n<\/p>\n<p><h3>\u56fe\u50cf\u683c\u5f0f\u8f6c\u6362<\/h3>\n<\/p>\n<p><p>Pillow\u5e93\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u56fe\u50cf\u4ece\u4e00\u79cd\u683c\u5f0f\u8f6c\u6362\u4e3a\u53e6\u4e00\u79cd\u683c\u5f0f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u6253\u5f00\u4e00\u4e2a\u56fe\u50cf\u6587\u4ef6<\/strong><\/h2>\n<p>image = Image.open(&#39;example.jpg&#39;)<\/p>\n<h2><strong>\u5c06\u56fe\u50cf\u4fdd\u5b58\u4e3aPNG\u683c\u5f0f<\/strong><\/h2>\n<p>image.save(&#39;example.png&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u6279\u91cf\u5904\u7406\u56fe\u50cf<\/h3>\n<\/p>\n<p><p>Pillow\u5e93\u8fd8\u53ef\u4ee5\u7528\u4e8e\u6279\u91cf\u5904\u7406\u56fe\u50cf\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u6279\u91cf\u8c03\u6574\u6587\u4ef6\u5939\u4e2d\u6240\u6709\u56fe\u50cf\u7684\u5927\u5c0f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>from PIL import Image<\/p>\n<h2><strong>\u5b9a\u4e49\u56fe\u50cf\u6587\u4ef6\u5939\u8def\u5f84<\/strong><\/h2>\n<p>image_folder = &#39;images\/&#39;<\/p>\n<h2><strong>\u904d\u5386\u6587\u4ef6\u5939\u4e2d\u7684\u6240\u6709\u56fe\u50cf\u6587\u4ef6<\/strong><\/h2>\n<p>for filename in os.listdir(image_folder):<\/p>\n<p>    if filename.endswith(&#39;.jpg&#39;):<\/p>\n<p>        # \u6253\u5f00\u56fe\u50cf\u6587\u4ef6<\/p>\n<p>        image = Image.open(os.path.join(image_folder, filename))<\/p>\n<p>        # \u8c03\u6574\u56fe\u50cf\u5927\u5c0f<\/p>\n<p>        resized_image = image.resize((200, 200))<\/p>\n<p>        # \u4fdd\u5b58\u8c03\u6574\u540e\u7684\u56fe\u50cf<\/p>\n<p>        resized_image.save(os.path.join(image_folder, &#39;resized_&#39; + filename))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e94\u3001\u56fe\u50cf\u7ed8\u5236\u548c\u6587\u672c\u6dfb\u52a0<\/h2>\n<\/p>\n<p><h3>\u7ed8\u5236\u56fe\u5f62<\/h3>\n<\/p>\n<p><p>Pillow\u5e93\u53ef\u4ee5\u7528\u4e8e\u5728\u56fe\u50cf\u4e0a\u7ed8\u5236\u56fe\u5f62\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u7ed8\u5236\u4e00\u4e2a\u77e9\u5f62\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image, ImageDraw<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u7a7a\u767d\u56fe\u50cf<\/strong><\/h2>\n<p>image = Image.new(&#39;RGB&#39;, (200, 200), &#39;white&#39;)<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u7ed8\u56fe\u5bf9\u8c61<\/strong><\/h2>\n<p>draw = ImageDraw.Draw(image)<\/p>\n<h2><strong>\u7ed8\u5236\u4e00\u4e2a\u77e9\u5f62<\/strong><\/h2>\n<p>draw.rectangle((50, 50, 150, 150), outline=&#39;black&#39;, fill=&#39;blue&#39;)<\/p>\n<h2><strong>\u663e\u793a\u7ed8\u5236\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u6dfb\u52a0\u6587\u672c<\/h3>\n<\/p>\n<p><p>Pillow\u5e93\u8fd8\u53ef\u4ee5\u5728\u56fe\u50cf\u4e0a\u6dfb\u52a0\u6587\u672c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image, ImageDraw, ImageFont<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u7a7a\u767d\u56fe\u50cf<\/strong><\/h2>\n<p>image = Image.new(&#39;RGB&#39;, (200, 200), &#39;white&#39;)<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u7ed8\u56fe\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;, 20)<\/p>\n<h2><strong>\u6dfb\u52a0\u6587\u672c<\/strong><\/h2>\n<p>draw.text((50, 50), &#39;Hello, World!&#39;, fill=&#39;black&#39;, font=font)<\/p>\n<h2><strong>\u663e\u793a\u6dfb\u52a0\u6587\u672c\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u516d\u3001\u56fe\u50cf\u7684\u9ad8\u7ea7\u5904\u7406<\/h2>\n<\/p>\n<p><h3>\u56fe\u50cf\u7684\u901a\u9053\u5206\u79bb\u548c\u5408\u5e76<\/h3>\n<\/p>\n<p><p>Pillow\u5e93\u53ef\u4ee5\u5206\u79bb\u56fe\u50cf\u7684\u5404\u4e2a\u989c\u8272\u901a\u9053\uff0c\u5e76\u5bf9\u5b83\u4eec\u8fdb\u884c\u5904\u7406\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u6253\u5f00\u4e00\u4e2a\u56fe\u50cf\u6587\u4ef6<\/strong><\/h2>\n<p>image = Image.open(&#39;example.jpg&#39;)<\/p>\n<h2><strong>\u5206\u79bb\u56fe\u50cf\u7684RGB\u901a\u9053<\/strong><\/h2>\n<p>r, g, b = image.split()<\/p>\n<h2><strong>\u5408\u5e76\u901a\u9053<\/strong><\/h2>\n<p>merged_image = Image.merge(&#39;RGB&#39;, (b, g, r))<\/p>\n<h2><strong>\u663e\u793a\u5408\u5e76\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>merged_image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56fe\u50cf\u7684\u900f\u660e\u5ea6\u5904\u7406<\/h3>\n<\/p>\n<p><p>Pillow\u5e93\u53ef\u4ee5\u5904\u7406\u56fe\u50cf\u7684\u900f\u660e\u5ea6\uff08Alpha\u901a\u9053\uff09\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u6253\u5f00\u4e00\u4e2a\u5e26Alpha\u901a\u9053\u7684\u56fe\u50cf\u6587\u4ef6<\/strong><\/h2>\n<p>image = Image.open(&#39;example.png&#39;)<\/p>\n<h2><strong>\u5206\u79bbAlpha\u901a\u9053<\/strong><\/h2>\n<p>r, g, b, a = image.split()<\/p>\n<h2><strong>\u8c03\u6574Alpha\u901a\u9053<\/strong><\/h2>\n<p>a = a.point(lambda i: i * 0.5)<\/p>\n<h2><strong>\u5408\u5e76\u901a\u9053<\/strong><\/h2>\n<p>transparent_image = Image.merge(&#39;RGBA&#39;, (r, g, b, a))<\/p>\n<h2><strong>\u663e\u793a\u8c03\u6574\u900f\u660e\u5ea6\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>transparent_image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56fe\u50cf\u7684\u76f4\u65b9\u56fe\u5747\u8861\u5316<\/h3>\n<\/p>\n<p><p>Pillow\u5e93\u53ef\u4ee5\u8fdb\u884c\u56fe\u50cf\u7684\u76f4\u65b9\u56fe\u5747\u8861\u5316\uff0c\u4ee5\u589e\u5f3a\u56fe\u50cf\u7684\u5bf9\u6bd4\u5ea6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image, ImageOps<\/p>\n<h2><strong>\u6253\u5f00\u4e00\u4e2a\u56fe\u50cf\u6587\u4ef6<\/strong><\/h2>\n<p>image = Image.open(&#39;example.jpg&#39;)<\/p>\n<h2><strong>\u8fdb\u884c\u76f4\u65b9\u56fe\u5747\u8861\u5316<\/strong><\/h2>\n<p>equalized_image = ImageOps.equalize(image)<\/p>\n<h2><strong>\u663e\u793a\u5747\u8861\u5316\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>equalized_image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u7684\u4ecb\u7ecd\u548c\u793a\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230Pillow\u5e93\u5728\u56fe\u50cf\u5904\u7406\u65b9\u9762\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u3002\u65e0\u8bba\u662f\u57fa\u672c\u7684\u56fe\u50cf\u6253\u5f00\u548c\u663e\u793a\uff0c\u8fd8\u662f\u9ad8\u7ea7\u7684\u56fe\u50cf\u5904\u7406\u548c\u8f6c\u6362\uff0cPillow\u5e93\u90fd\u80fd\u591f\u6ee1\u8db3\u4e0d\u540c\u7684\u9700\u6c42\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u5bf9\u4f60\u4e86\u89e3\u548c\u4f7f\u7528Pillow\u5e93\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python 3\u4e2d\u5b89\u88c5PIL.Image\u6a21\u5757\uff1f<\/strong><br \/>PIL\uff08Python Imaging Library\uff09\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u56fe\u50cf\u5904\u7406\u5e93\uff0c\u4f46\u5b83\u5df2\u7ecf\u88abPillow\u5e93\u6240\u53d6\u4ee3\u3002\u8981\u5b89\u88c5Pillow\u5e76\u4f7f\u7528\u5176\u4e2d\u7684Image\u6a21\u5757\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\uff1a\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>pip install Pillow<\/code>\uff0c\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u5c31\u53ef\u4ee5\u901a\u8fc7<code>from PIL import Image<\/code>\u6765\u5bfc\u5165Image\u6a21\u5757\u5e76\u5f00\u59cb\u4f7f\u7528\u3002<\/p>\n<p><strong>Pillow\u5e93\u548cPIL\u5e93\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/strong><br \/>Pillow\u662fPIL\u7684\u4e00\u4e2a\u5206\u652f\uff0c\u65e8\u5728\u4e3aPython 3\u63d0\u4f9b\u66f4\u597d\u7684\u652f\u6301\u548c\u66f4\u591a\u7684\u529f\u80fd\u3002Pillow\u4e0d\u4ec5\u517c\u5bb9PIL\u7684\u529f\u80fd\uff0c\u8fd8\u4fee\u590d\u4e86\u8bb8\u591a\u5df2\u77e5\u7684\u9519\u8bef\u5e76\u589e\u52a0\u4e86\u5bf9\u65b0\u683c\u5f0f\u7684\u652f\u6301\u3002\u56e0\u6b64\uff0c\u5efa\u8bae\u5728\u65b0\u7684\u9879\u76ee\u4e2d\u4f7f\u7528Pillow\u800c\u4e0d\u662fPIL\u3002<\/p>\n<p><strong>\u5b89\u88c5Pillow\u540e\uff0c\u5982\u4f55\u9a8c\u8bc1\u662f\u5426\u6210\u529f\uff1f<\/strong><br \/>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u7f16\u5199\u7b80\u5355\u7684Python\u4ee3\u7801\u6765\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f\u3002\u5728Python\u4ea4\u4e92\u5f0f\u73af\u5883\u6216\u811a\u672c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801\uff1a  <\/p>\n<pre><code class=\"language-python\">from PIL import Image\nprint(Image.__version__)\n<\/code><\/pre>\n<p>\u5982\u679c\u6ca1\u6709\u9519\u8bef\uff0c\u5e76\u4e14\u80fd\u591f\u6210\u529f\u6253\u5370\u51fa\u7248\u672c\u53f7\uff0c\u8bf4\u660ePillow\u5b89\u88c5\u6210\u529f\uff0c\u53ef\u4ee5\u6b63\u5e38\u4f7f\u7528\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python3\u4e2d\u5b89\u88c5PIL.Image\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a 1\u3001\u4f7f\u7528pip\u5b89\u88c5Pillow\u5e93 \u5728Python3\u4e2d\uff0cP [&hellip;]","protected":false},"author":3,"featured_media":1051513,"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\/1051505"}],"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=1051505"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1051505\/revisions"}],"predecessor-version":[{"id":1051517,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1051505\/revisions\/1051517"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1051513"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1051505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1051505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1051505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}