Created
May 20, 2020 23:16
-
-
Save jillesme/c4c336d9a174db1549897d3f2534520c to your computer and use it in GitHub Desktop.
Django in-memory image creation for testing
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 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