Jesse Vogt
Jesse Vogt

Reputation: 16509

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

I have 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?

Upvotes: 29

Views: 85877

Answers (2)

Armandas
Armandas

Reputation: 2396

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

Upvotes: 41

scvalex
scvalex

Reputation: 15345

Have a look at PIL and pyGame. Both of them allow you to draw on a canvas and then save it to a file.

Upvotes: 6

Related Questions