summaryrefslogtreecommitdiff
path: root/docs/posts/2020-01-14-Converting-between-PIL-NumPy.html
diff options
context:
space:
mode:
Diffstat (limited to 'docs/posts/2020-01-14-Converting-between-PIL-NumPy.html')
-rw-r--r--docs/posts/2020-01-14-Converting-between-PIL-NumPy.html12
1 files changed, 8 insertions, 4 deletions
diff --git a/docs/posts/2020-01-14-Converting-between-PIL-NumPy.html b/docs/posts/2020-01-14-Converting-between-PIL-NumPy.html
index 293da91..1db31be 100644
--- a/docs/posts/2020-01-14-Converting-between-PIL-NumPy.html
+++ b/docs/posts/2020-01-14-Converting-between-PIL-NumPy.html
@@ -43,7 +43,8 @@
<main>
<h1>Converting between image and NumPy array</h1>
-<div class="codehilite"><pre><span></span><code><span class="kn">import</span> <span class="nn">numpy</span>
+<div class="codehilite">
+<pre><span></span><code><span class="kn">import</span> <span class="nn">numpy</span>
<span class="kn">import</span> <span class="nn">PIL</span>
<span class="c1"># Convert PIL Image to NumPy array</span>
@@ -52,16 +53,19 @@
<span class="c1"># Convert array to Image</span>
<span class="n">img</span> <span class="o">=</span> <span class="n">PIL</span><span class="o">.</span><span class="n">Image</span><span class="o">.</span><span class="n">fromarray</span><span class="p">(</span><span class="n">arr</span><span class="p">)</span>
-</code></pre></div>
+</code></pre>
+</div>
<h2>Saving an Image</h2>
-<div class="codehilite"><pre><span></span><code><span class="k">try</span><span class="p">:</span>
+<div class="codehilite">
+<pre><span></span><code><span class="k">try</span><span class="p">:</span>
<span class="n">img</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">destination</span><span class="p">,</span> <span class="s2">&quot;JPEG&quot;</span><span class="p">,</span> <span class="n">quality</span><span class="o">=</span><span class="mi">80</span><span class="p">,</span> <span class="n">optimize</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">progressive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">IOError</span><span class="p">:</span>
<span class="n">PIL</span><span class="o">.</span><span class="n">ImageFile</span><span class="o">.</span><span class="n">MAXBLOCK</span> <span class="o">=</span> <span class="n">img</span><span class="o">.</span><span class="n">size</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">img</span><span class="o">.</span><span class="n">size</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="n">img</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">destination</span><span class="p">,</span> <span class="s2">&quot;JPEG&quot;</span><span class="p">,</span> <span class="n">quality</span><span class="o">=</span><span class="mi">80</span><span class="p">,</span> <span class="n">optimize</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">progressive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
-</code></pre></div>
+</code></pre>
+</div>
<script data-isso="//comments.navan.dev/"
src="//comments.navan.dev/js/embed.min.js"></script>