Skip to content

Instantly share code, notes, and snippets.

@hwshim0810 hwshim0810/image_util.py
Last active Dec 31, 2018

Embed
What would you like to do?
Create temporary imagefile
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
You can’t perform that action at this time.