[Fixed]-How can I created a PIL Image from an in-memory file?

17👍

Note that Django’s ImageField inherits the open method from FieldFile. This returns a stream object that can be passed to PIL’s Image.open (the standard factory method for creating Image objects from an image stream):

stream = imagefield.open()
image = Image.open(stream)
stream.close()
# ... and then save image with: image.save(outfile, format, options)

See PIL Image documentation.

20👍

Have you tried StringIO ?

see the docs http://effbot.org/imagingbook/introduction.htm#more-on-reading-images

#Reading from a string 
import StringIO

im = Image.open(StringIO.StringIO(buffer))

Leave a comment