27

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?

mishap
  • 8,176
  • 14
  • 61
  • 92
Jesse Vogt
  • 16,229
  • 16
  • 59
  • 72

2 Answers2

39

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')
Armandas
  • 2,276
  • 1
  • 22
  • 27
  • 2
    More useful examples: http://stackoverflow.com/questions/12062920/how-do-i-create-an-image-in-pil-using-a-list-of-rgb-tuples – Anderson Green Dec 28 '13 at 05:38
6

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

scvalex
  • 14,931
  • 2
  • 34
  • 43
  • Further information about generation of images using Pygame [can be found here](https://www.google.com/search?q=pygame+generate+image&oq=pygame+generate+image&aqs=chrome..69i57.2663j0j8&sourceid=chrome&espv=210&es_sm=93&ie=UTF-8). – Anderson Green Dec 28 '13 at 05:20