diff options
author | Navan Chauhan <navanchauhan@gmail.com> | 2020-01-14 23:03:43 +0530 |
---|---|---|
committer | Navan Chauhan <navanchauhan@gmail.com> | 2020-01-14 23:03:43 +0530 |
commit | 81ae1cfaf44f9f188e35936a660e82a4e9af238e (patch) | |
tree | 81e272000149357b93b8f0e7af809375979642af /posts/2020-01-14-Converting-between-PIL-NumPy | |
parent | 562c929cd8b75d08d8ca368e0400c70188cd35a4 (diff) |
Publish deploy 2020-01-14 23:03
Diffstat (limited to 'posts/2020-01-14-Converting-between-PIL-NumPy')
-rw-r--r-- | posts/2020-01-14-Converting-between-PIL-NumPy/index.html | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/posts/2020-01-14-Converting-between-PIL-NumPy/index.html b/posts/2020-01-14-Converting-between-PIL-NumPy/index.html new file mode 100644 index 0000000..fb685a2 --- /dev/null +++ b/posts/2020-01-14-Converting-between-PIL-NumPy/index.html @@ -0,0 +1,15 @@ +<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"/><meta name="og:site_name" content="Navan Chauhan"/><link rel="canonical" href="https://navanchauhan.github.io/posts/2020-01-14-Converting-between-PIL-NumPy"/><meta name="twitter:url" content="https://navanchauhan.github.io/posts/2020-01-14-Converting-between-PIL-NumPy"/><meta name="og:url" content="https://navanchauhan.github.io/posts/2020-01-14-Converting-between-PIL-NumPy"/><title>Converting between image and NumPy array | Navan Chauhan</title><meta name="twitter:title" content="Converting between image and NumPy array | Navan Chauhan"/><meta name="og:title" content="Converting between image and NumPy array | Navan Chauhan"/><meta name="description" content="Short code snippet for converting between PIL image and NumPy arrays."/><meta name="twitter:description" content="Short code snippet for converting between PIL image and NumPy arrays."/><meta name="og:description" content="Short code snippet for converting between PIL image and NumPy arrays."/><meta name="twitter:card" content="summary"/><link rel="stylesheet" href="/styles.css" type="text/css"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><link rel="shortcut icon" href="/images/favicon.png" type="image/png"/><link rel="alternate" href="/feed.rss" type="application/rss+xml" title="Subscribe to Navan Chauhan"/><meta name="twitter:image" content="https://navanchauhan.github.io/images/logo.png"/><meta name="og:image" content="https://navanchauhan.github.io/images/logo.png"/></head><body class="item-page"><header><div class="wrapper"><a class="site-name" href="/">Navan Chauhan</a><nav><ul><li><a class="selected" href="/posts">Posts</a></li><li><a href="/publications">Publications</a></li><li><a href="/about">About Me</a></li><li><a href="https://navanchauhan.github.io/repo">Repo</a></li></ul></nav></div></header><div class="wrapper"><article><div class="content"><span class="reading-time">🕑 0 minute read.</span><h1>Converting between image and NumPy array</h1><pre><code>import numpy +import PIL + +# Convert PIL Image to NumPy array +img = PIL.Image.open("foo.jpg") +arr = numpy.array(img) + +# Convert array to Image +img = PIL.Image.fromarray(arr) +</code></pre><h2>Saving an Image</h2><pre><code>try: + img.save(destination, "JPEG", quality=80, optimize=True, progressive=True) +except IOError: + PIL.ImageFile.MAXBLOCK = img.size[0] * img.size[1] + img.save(destination, "JPEG", quality=80, optimize=True, progressive=True) +</code></pre></div><span>Tagged with: </span><ul class="tag-list"><li><a href="/tags/codesnippet">code-snippet</a></li><li><a href="/tags/tutorial">tutorial</a></li></ul></article></div><footer><p>Made with ❤️ using <a href="https://github.com/johnsundell/publish">Publish</a></p><p><a href="/feed.rss">RSS feed</a></p></footer></body></html>
\ No newline at end of file |