Using PIL 1.1.7, redis-2.7.2 pip module and redis-2.4.10 I managed to get this to work:
import Image import redis import StringIO output = StringIO.StringIO() im = Image.open("/home/cwgem/Pictures/portrait.png") im.save(output, format=im.format) r = redis.StrictRedis(host='localhost') r.set('imagedata', output.getvalue()) output.close()
I found that Image.tostring not reliable, so this method uses StringIO to make the string look like a file. format=im.format necessary because StringIO has no extension. Then I tested that the image data was saved in order:
redis-cli --raw get 'imagedata' >test.png
and confirmation that I received the image.
cwgem source share