Last active
December 31, 2018 05:25
-
-
Save hwshim0810/f25b462075b32299d7cdebfaf8cbe9a3 to your computer and use it in GitHub Desktop.
Create temporary imagefile
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
import tempfile | |
from io import BytesIO | |
from PIL import Image | |
def get_test_image(): | |
file = BytesIO() | |
image = Image.new('RGBA', size=(50, 50), color=(155, 0, 0)) | |
image.save(file, 'png') | |
file.name = 'test_image.png' | |
file.seek(0) | |
return file | |
def get_temporary_image_name(): | |
temp_file = tempfile.NamedTemporaryFile() | |
image = Image.new('RGBA', (200, 200), (255, 0, 0)) | |
image.save(temp_file, 'png') | |
return temp_file.name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment