python - Writing an image from PIL's 'Image' class into a model instance's ImageFile field -


i want load image , manipulate using python imaging library , store in model's imagefield. following outlines i'm trying do, minus manipulation:

#the model      class djinfo(models.model):         dj_name = models.charfield(max_length=30)         picture = models.imagefield(upload_to="images/dj_pictures")         email_address = models.emailfield()      #what i'm trying do:      import tempfile     import image     artists.models import djinfo      image = image.open('ticket.png')     tf = tempfile.tempfile(mode='r+b')     image.save(tf, 'png')      dji=djinfo()     dji.picture.save('test.png', tf) 

you this:

image = image.open('test.png') tf = tempfile.temporaryfile(mode='r+b') name = tf.name del tf image.save(name, 'png') dji=djinfo() dji.picture.save('test.png', name) 

but suspect there better way using cstringio or other buffer object saving step of writing temp file hdd.

is this same question?:


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -