How to change image format without writing it to disk using Python Pillow
<p>I got Pillow image that i got from the Internet:</p>

<pre><code>response= urllib2.urlopen(&lt;url to gif image&gt;)
img = Image.open(cStringIO.StringIO(response.read()))
</code></pre>

<p>I want to use it with tesserocr but it wont work with GIF images.</p>

<p>If I save the image as PNG <code>img.save("tmp.png")</code> and load it <code>img = Image.open("tmp.png")</code> everything works.</p>

<p>Is there a way to do this conversion without writing to disk?</p>

<p>The solution was very simple:</p>

<pre><code>response= urllib2.urlopen(&lt;url to gif image&gt;)
img = Image.open(cStringIO.StringIO(response.read()))
img = img.convert("RGB")
</code></pre>

<p>Note that you need to remove the alpha channel info to make image compatible with tesserocr</p>

python python-2.7 pillow cstringio