Created
July 25, 2019 16:58
-
-
Save aj07mm/b96495f9b9ba29044c35d507cd0d41de to your computer and use it in GitHub Desktop.
get_image_file.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_image_file(name='test.png', ext='png', size=(50, 50), color=(256, 0, 0)): | |
from StringIO import StringIO | |
from PIL import Image | |
from django.core.files import File | |
file_obj = StringIO() | |
file_obj.write('') | |
image = Image.new("RGBA", size=size, color=color) | |
image.save(file_obj, ext) | |
file_obj.seek(0) | |
return File(file_obj, name=name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://docs.djangoproject.com/en/2.2/topics/http/file-uploads/