{"id":4632,"date":"2024-01-18T20:01:57","date_gmt":"2024-01-18T20:01:57","guid":{"rendered":"https:\/\/ibex.tech\/python\/?p=4632"},"modified":"2024-01-19T15:40:09","modified_gmt":"2024-01-19T15:40:09","slug":"save-image","status":"publish","type":"post","link":"https:\/\/ibex.tech\/python\/images\/pillow\/save-image","title":{"rendered":"Save image"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Save to file<\/h4>\n\n\n\n<p>You can specify the file type when you come to save<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    image1.save(\"C:\/MyDirectory\/myimage.jpg\"), quality=95)<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Output as a byte array<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>import io\nfrom PIL import Image\n\n    image1_byte_array = io.BytesIO()\n    image1.save(image1_byte_array, format='JPG')\n    image1_byte_array = image1_byte_array.getvalue()\n    return image1_byte_array\n\n#You could then save this byte array toi a file using:\n    with open(\"C:\/MyDirectory\/myimage.jpg\"), \"wb\") as file1:\n        file1.write(image1_byte_array)<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Save to file You can specify the file type when you come to save Output as a byte array<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[367],"tags":[],"class_list":["post-4632","post","type-post","status-publish","format-standard","hentry","category-pillow"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4632","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/comments?post=4632"}],"version-history":[{"count":5,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4632\/revisions"}],"predecessor-version":[{"id":4649,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4632\/revisions\/4649"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/media?parent=4632"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/categories?post=4632"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/tags?post=4632"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}