Saving Ndarray to InMemoryUploadedFile
이미지를 조작하는 ndarray에서 모델에 저장하기 위해 inmemoryuploadedfile 형태로 바꿔야하는 경우가 있다.
http://stackoverflow.com/questions/3723220/how-do-you-convert-a-pil-image-to-a-django-file
import StringIO
from django.core.files.uploadedfile import InMemoryUploadedFile
# Create a file-like object to write thumb data (thumb data previously created
# using PIL, and stored in variable 'thumb')
thumb_io = StringIO.StringIO()
thumb.save(thumb_io, format='JPEG')
# Create a new Django file-like object to be used in models as ImageField using
# InMemoryUploadedFile. If you look at the source in Django, a
# SimpleUploadedFile is essentially instantiated similarly to what is shown here
thumb_file = InMemoryUploadedFile(thumb_io, None, 'foo.jpg', 'image/jpeg',
thumb_io.len, None)
# Once you have a Django file-like object, you may assign it to your ImageField
# and save.
...