{"id":282,"date":"2020-12-21T11:41:46","date_gmt":"2020-12-21T16:41:46","guid":{"rendered":"https:\/\/www.millamilla.com\/?p=282"},"modified":"2020-12-21T12:14:20","modified_gmt":"2020-12-21T17:14:20","slug":"learning-about-the-pillow-python-library","status":"publish","type":"post","link":"https:\/\/www.millamilla.com:443\/?p=282","title":{"rendered":"Learning about the Pillow Python Library"},"content":{"rendered":"\n<p>Spending some time brushing up on Python.&nbsp; Spent some time learning about the Pillow 8.0.1 library in Python 3.9.1.<\/p>\n\n\n\n<p>The <a href=\"https:\/\/cdn.britannica.com\/s:800x450,c:crop\/83\/195983-138-66807699\/numbers-tiger-populations.jpg\">image<\/a> I started with.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom PIL import Image\nimport os\n\nif __name__ == &#039;__main__&#039;:\n    # Open an image to get some basic info\n    infile = &quot;images\/numbers-tiger-populations.jpg&quot;\n    im = Image.open(infile)\n    print(f&quot;&quot;&quot;\nbits {im.bits}\nmode {im.mode}\nsize {im.size}\n    &quot;&quot;&quot;)\n\n    # Show the image using the local viewer\n    input(&quot;Press enter when you are ready to see the image.&quot;)\n    im.show()\n\n    # Create a thumbnail\n    size = (128, 128)\n    outfile = os.path.splitext(infile)&#x5B;0] + &quot;.thumbnail&quot;\n    with Image.open(infile) as im:\n        im.thumbnail(size)\n        im.save(outfile, &quot;JPEG&quot;)\n\n    # Show the thumbnail\n    im = Image.open(outfile)\n    input(&quot;Press enter when you are ready to see the thumbnail.&quot;)\n    im.show()\n\n    # convert to grayscale\n    im = Image.open(infile).convert(&#039;LA&#039;)\n\n    # Show the grayscale\n    input(&quot;Press enter when you are ready to see the grayscale.&quot;)\n    im.show()\n\n<\/pre><\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>Spending some time brushing up on Python.&nbsp; Spent some time learning about the Pillow 8.0.1 library in Python 3.9.1. The image I started with.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-282","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.millamilla.com:443\/index.php?rest_route=\/wp\/v2\/posts\/282","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.millamilla.com:443\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.millamilla.com:443\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.millamilla.com:443\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.millamilla.com:443\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=282"}],"version-history":[{"count":9,"href":"https:\/\/www.millamilla.com:443\/index.php?rest_route=\/wp\/v2\/posts\/282\/revisions"}],"predecessor-version":[{"id":294,"href":"https:\/\/www.millamilla.com:443\/index.php?rest_route=\/wp\/v2\/posts\/282\/revisions\/294"}],"wp:attachment":[{"href":"https:\/\/www.millamilla.com:443\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=282"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.millamilla.com:443\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=282"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.millamilla.com:443\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=282"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}