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
Post a Comment