{"id":1216,"date":"2020-10-01T02:48:25","date_gmt":"2020-10-01T02:48:25","guid":{"rendered":"http:\/\/learnlearn.uk\/python\/?page_id=1216"},"modified":"2022-10-14T09:14:56","modified_gmt":"2022-10-14T09:14:56","slug":"editing-images-python-pillow","status":"publish","type":"page","link":"https:\/\/learnlearn.uk\/python\/editing-images-python-pillow\/","title":{"rendered":"Editing Images with Python Pillow"},"content":{"rendered":"<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">Introduction<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Introduction<\/h3>\n<p>Python Pillow is a great image editing module that allows you to perform a number of image editing tasks using Python.<\/p>\n<p>Examples of things you can do are:<\/p>\n<ul>\n<li>Edit the image size and dimensions<\/li>\n<li>Rotate an image<\/li>\n<li>Change the brightness of an image<\/li>\n<li>Edit the colors of individual pixels in an image<\/li>\n<\/ul>\n<p>This is especially useful if you need to process a large number of images using the same process!<\/p>\n<p><strong>Installing Pillow<\/strong><\/p>\n<p>Pillow usually does not come installed as standard, so you may need to install it on your computer first to use it.<\/p>\n<p><a href=\"https:\/\/pillow.readthedocs.io\/en\/stable\/installation.html\">Here is the link for how to install it<\/a><\/p>\n\n<\/div><h2 class=\"tabtitle\">Getting Started<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Getting Started<\/h3>\n<p>Before we try to edit the image, we should first get a feel for the program.<\/p>\n<p>Download the image below and save it to a folder on your computer. Open the CMD\/Terminal program and navigate to the correct folder that you just saved the file to.<\/p>\n<p><a href=\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2020\/10\/dogememe.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-1219 size-medium\" src=\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2020\/10\/dogememe-300x300.png?_t=1601594950\" alt=\"\" width=\"300\" height=\"300\" srcset=\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2020\/10\/dogememe-300x300.png 300w, https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2020\/10\/dogememe-150x150.png 150w, https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2020\/10\/dogememe.png 612w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><strong>Opening Images<\/strong><\/p>\n<p>Once you are in the correct folder in the terminal open up the Python interactive interpreter by typing python or python3.<\/p>\n<p>Inside the interpreter import the Image class from Pillow and load the image by typing:<\/p>\n<pre>from PIL import Image\r\n\r\nim = image.open('dogememe.png')\r\n\r\n<\/pre>\n<p>If you have any problems opening the file check that you opened Python in the same directory as where the image is located (leave Python and type <strong>ls<\/strong> or <strong>dir<\/strong> to check you can see the image).<\/p>\n<p>Investigate the image.<\/p>\n<p>Try out the following code and see what each one does.<\/p>\n<ul>\n<li>im.height<\/li>\n<li>im.width<\/li>\n<li>im.size<\/li>\n<li>im.getbands()<\/li>\n<li>im.getbbox()<\/li>\n<li>im.getcolors()<\/li>\n<li>im.getexif()<\/li>\n<li>im.getextrema()<\/li>\n<li>im.getpalette()<\/li>\n<li>im.getpixel()<\/li>\n<li>im.getdata()<\/li>\n<li>im.gethistogram()<\/li>\n<\/ul>\n\n<\/div><h2 class=\"tabtitle\">Image Data<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Image Data<\/h3>\n<p>Try the following code<\/p>\n<pre>im.getdata()<\/pre>\n<p>What do you see? What do the numbers represent?<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Python Pillow is a great image editing module that allows you to perform a number of image editing tasks using Python. Examples of things you can do are: Edit the image size and dimensions Rotate an image Change the brightness of an image Edit the colors of individual pixels in an image This is&hellip;&nbsp;<a href=\"https:\/\/learnlearn.uk\/python\/editing-images-python-pillow\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Editing Images with Python Pillow<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":70,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Editing Images with Python Pillow - Python<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/learnlearn.uk\/python\/editing-images-python-pillow\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Editing Images with Python Pillow - Python\" \/>\n<meta property=\"og:description\" content=\"Introduction Python Pillow is a great image editing module that allows you to perform a number of image editing tasks using Python. Examples of things you can do are: Edit the image size and dimensions Rotate an image Change the brightness of an image Edit the colors of individual pixels in an image This is&hellip;&nbsp;Read More &raquo;Editing Images with Python Pillow\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnlearn.uk\/python\/editing-images-python-pillow\/\" \/>\n<meta property=\"og:site_name\" content=\"Python\" \/>\n<meta property=\"article:modified_time\" content=\"2022-10-14T09:14:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2020\/10\/dogememe-300x300.png?_t=1601594950\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learnlearn.uk\/python\/editing-images-python-pillow\/\",\"url\":\"https:\/\/learnlearn.uk\/python\/editing-images-python-pillow\/\",\"name\":\"Editing Images with Python Pillow - Python\",\"isPartOf\":{\"@id\":\"https:\/\/learnlearn.uk\/python\/#website\"},\"datePublished\":\"2020-10-01T02:48:25+00:00\",\"dateModified\":\"2022-10-14T09:14:56+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/learnlearn.uk\/python\/editing-images-python-pillow\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnlearn.uk\/python\/editing-images-python-pillow\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnlearn.uk\/python\/editing-images-python-pillow\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Python Unit Home\",\"item\":\"https:\/\/learnlearn.uk\/python\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Editing Images with Python Pillow\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learnlearn.uk\/python\/#website\",\"url\":\"https:\/\/learnlearn.uk\/python\/\",\"name\":\"Python\",\"description\":\"Programming\",\"publisher\":{\"@id\":\"https:\/\/learnlearn.uk\/python\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learnlearn.uk\/python\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/learnlearn.uk\/python\/#organization\",\"name\":\"Python\",\"url\":\"https:\/\/learnlearn.uk\/python\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/learnlearn.uk\/python\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2019\/03\/LearnLearnLogowhite.png\",\"contentUrl\":\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2019\/03\/LearnLearnLogowhite.png\",\"width\":710,\"height\":98,\"caption\":\"Python\"},\"image\":{\"@id\":\"https:\/\/learnlearn.uk\/python\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Editing Images with Python Pillow - Python","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/learnlearn.uk\/python\/editing-images-python-pillow\/","og_locale":"en_GB","og_type":"article","og_title":"Editing Images with Python Pillow - Python","og_description":"Introduction Python Pillow is a great image editing module that allows you to perform a number of image editing tasks using Python. Examples of things you can do are: Edit the image size and dimensions Rotate an image Change the brightness of an image Edit the colors of individual pixels in an image This is&hellip;&nbsp;Read More &raquo;Editing Images with Python Pillow","og_url":"https:\/\/learnlearn.uk\/python\/editing-images-python-pillow\/","og_site_name":"Python","article_modified_time":"2022-10-14T09:14:56+00:00","og_image":[{"url":"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2020\/10\/dogememe-300x300.png?_t=1601594950"}],"twitter_card":"summary_large_image","twitter_misc":{"Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/learnlearn.uk\/python\/editing-images-python-pillow\/","url":"https:\/\/learnlearn.uk\/python\/editing-images-python-pillow\/","name":"Editing Images with Python Pillow - Python","isPartOf":{"@id":"https:\/\/learnlearn.uk\/python\/#website"},"datePublished":"2020-10-01T02:48:25+00:00","dateModified":"2022-10-14T09:14:56+00:00","breadcrumb":{"@id":"https:\/\/learnlearn.uk\/python\/editing-images-python-pillow\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnlearn.uk\/python\/editing-images-python-pillow\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/learnlearn.uk\/python\/editing-images-python-pillow\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Python Unit Home","item":"https:\/\/learnlearn.uk\/python\/"},{"@type":"ListItem","position":2,"name":"Editing Images with Python Pillow"}]},{"@type":"WebSite","@id":"https:\/\/learnlearn.uk\/python\/#website","url":"https:\/\/learnlearn.uk\/python\/","name":"Python","description":"Programming","publisher":{"@id":"https:\/\/learnlearn.uk\/python\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learnlearn.uk\/python\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/learnlearn.uk\/python\/#organization","name":"Python","url":"https:\/\/learnlearn.uk\/python\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/learnlearn.uk\/python\/#\/schema\/logo\/image\/","url":"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2019\/03\/LearnLearnLogowhite.png","contentUrl":"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2019\/03\/LearnLearnLogowhite.png","width":710,"height":98,"caption":"Python"},"image":{"@id":"https:\/\/learnlearn.uk\/python\/#\/schema\/logo\/image\/"}}]}},"rttpg_featured_image_url":null,"rttpg_author":{"display_name":"learnlearnadmin","author_link":"https:\/\/learnlearn.uk\/python\/author\/learnlearnadmin\/"},"rttpg_comment":0,"rttpg_category":null,"rttpg_excerpt":"Introduction Python Pillow is a great image editing module that allows you to perform a number of image editing tasks using Python. Examples of things you can do are: Edit the image size and dimensions Rotate an image Change the brightness of an image Edit the colors of individual pixels in an image This is&hellip;&nbsp;Read&hellip;","_links":{"self":[{"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/pages\/1216"}],"collection":[{"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/comments?post=1216"}],"version-history":[{"count":6,"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/pages\/1216\/revisions"}],"predecessor-version":[{"id":1337,"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/pages\/1216\/revisions\/1337"}],"wp:attachment":[{"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/media?parent=1216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}