More specifically, I want to change the filetype of an image uploaded through a Django ImageField.
My current thinking is to created a custom ImageField and overwrite the save method to manipulate the file.
I've having trouble getting an in memory file to because a PIL Image instance.
Thanks for the help.
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))
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With