Skip to content

Instantly share code, notes, and snippets.

@aj07mm
Created July 25, 2019 16:58
Show Gist options
  • Save aj07mm/b96495f9b9ba29044c35d507cd0d41de to your computer and use it in GitHub Desktop.
Save aj07mm/b96495f9b9ba29044c35d507cd0d41de to your computer and use it in GitHub Desktop.
get_image_file.py
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)
@aj07mm
Copy link
Author

aj07mm commented Jul 25, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment