Skip to content

Instantly share code, notes, and snippets.

@hwshim0810
Last active December 31, 2018 05:25
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 hwshim0810/f25b462075b32299d7cdebfaf8cbe9a3 to your computer and use it in GitHub Desktop.
Save hwshim0810/f25b462075b32299d7cdebfaf8cbe9a3 to your computer and use it in GitHub Desktop.
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