Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

How to get a mock image in django?

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)
Comment

PREVIOUS NEXT
Code Example
Python :: Get Project Parameter Dynamo Revit 
Python :: flask files not updating 
Python :: clicking items in selenium 
Python :: countvectorizer minimum frequency 
Python :: how to use python-socker.io with fast api 
Python :: cant access a dataframe imported using pickle 
Python :: Which of the following statements is used to create an empty set in Python? 
Python :: get current worker id multiprocessing 
Python :: pairwise swap in data structure in python 
Python :: convert .tiff image stack to unit8 format 
Python :: import curses module in python 
Python :: access value of posted object python 
Python :: return tuples form functions in Python 
Python :: django send_mail not working in testcase 
Python :: django array of dates 
Python :: How to test if a webpage is an image python requests 
Python :: iris data pandas scatterplot 
Python :: superpixel 
Python :: naiveDateTime last week from current time 
Python :: django extract array from post matrix 
Python :: re mobile no validate python 
Python :: fetch api flask url redirect 
Python :: is not and != difference in python 
Python :: torch.tensor.expand 
Python :: create a distance matrix from a coordinate matrix in python 
Python :: performance of extend vs append loop 
Python :: pycharm display info of function 
Python :: python convert py to exe 
Python :: tkinter call function in mainloop 
Python :: python merge sort 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =