Skip to content

Instantly share code, notes, and snippets.

@jillesme
Created May 20, 2020 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jillesme/c4c336d9a174db1549897d3f2534520c to your computer and use it in GitHub Desktop.
Save jillesme/c4c336d9a174db1549897d3f2534520c to your computer and use it in GitHub Desktop.
Django in-memory image creation for testing
def create_image(self, height=50, width=50, format="jpeg"):
image = BytesIO()
memory_image = Image.new("RGB", (height, width))
memory_image.save(image, format=format)
return SimpleUploadedFile(f"test.{format}", image.getvalue(), f"image/{format}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment