In Python, how do I easily generate an image file from some source data?

Jesse Vogt picture Jesse Vogt · Jun 24, 2009 · Viewed 53.6k times · Source

I have some some data that I would like to visualize. Each byte of the source data roughly corresponds to a pixel value of the image.

What is the easiest way to generate an image file (bitmap?) using Python?

Answer

Armandas picture Armandas · Jun 24, 2009

You can create images with a list of pixel values using Pillow:

from PIL import Image

img = Image.new('RGB', (width, height))
img.putdata(my_list)
img.save('image.png')