title: Fetch image from internet, modify and insert to database in python
body: <p>I'm trying to save images from one webpage to the database of another.</p>
  
  <p>Here is a cut down version of the code:</p>
  
  <pre><code>POSTER_SIZE = (200, 310)
  
  LargePoster = urllib2.urlopen(PosterURL).read()
  SmallPoster = LargePoster.resize(POSTER_SIZE, Image.ANTIALIAS)
  
  conn = MySQLdb.connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, charset='utf8')
  cur = conn()
  cur.execute("UPDATE `table` SET `poster`=%s WHERE `id`=%d", (SmallPoster, ID))
  cur.close()
  </code></pre>
  
  <p><strong>Note:</strong> <em>I do NOT want to keep the aspect ratio, so do not suggest <code>Image.thumbnail()</code> unless it can stretch it.</em></p>
  
  <p>As you can see, I retrieve the image using <code>urlopen()</code> and <code>read()</code> but it returns a string. I need this string to be of class Image so I can manipulate it using PIL/Pillow and then later have it output as a string so I can send it to the database.</p>
  
  <p>I know for a fact that all the images are compressed using JPEG.</p>
  
  <p><strong>Updated code for Peter</strong></p>
  
  <pre><code>LargePosterString = urllib2.urlopen(MovieMeta['poster']).read()
  LargePosterImage = Image.open(StringIO(LargePosterString))
  
  SmallPosterImage = LargePosterImage.resize(POSTER_SIZE, Image.ANTIALIAS)
  SmallPosterString = StringIO()
  
  Format = 'JPEG'
  SmallPosterImage.save(SmallPosterString.getvalue(), Format)
  </code></pre>