1
Here is how I create images for testing purposes, I found this solution in the SO, maybe it helps you.
from StringIO import StringIO
from PIL import Image
.....
def create_image_file(self):
image_file = StringIO()
image = Image.new('RGBA', size=(50, 50), color=(256, 0, 0))
image.save(image_file, 'png')
image_file.seek(0)
return ContentFile(image_file.read(), 'test.png')
Source:stackexchange.com