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.

Revisions

  1. aj07mm created this gist Jul 25, 2019.
    11 changes: 11 additions & 0 deletions get_image_file.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    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)