I'm trying to save images from one webpage to the database of another.
Here is a cut down version of the 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()
Note: I do NOT want to keep the aspect ratio, so do not suggest Image.thumbnail() unless it can stretch it.
As you can see, I retrieve the image using urlopen() and read() 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.
I know for a fact that all the images are compressed using JPEG.
Updated code for Peter
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)