📅  最后修改于: 2022-03-11 14:46:19.945000             🧑  作者: Mango
from io import StringIO
from PIL import Image
from django.core.files.base import File
# Just invoke this function and you'll get a png file
def get_mock_img(name='test.png', ext='png', size=(50, 50), color=(256, 0, 0)):
file_obj = StringIO()
image = Image.new("RGB", size=size, color=color)
image.save(file_obj, ext)
file_obj.seek(0)
return File(file_obj, name=name)