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?
new() method creates a new image with the given mode and size. Size is given as a (width, height)-tuple, in pixels. The color is given as a single value for single-band images, and a tuple for multi-band images (with one value for each band).
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')
Have a look at PIL and pyGame. Both of them allow you to draw on a canvas and then save it to a file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With