Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - How to save a list as an image?

I generate a regular list. Is it possible to save this list as a JPEG image or PNG or whatever so that I can open the image and look at it? I am currently trying to figure it out using the python imaging library (PIL).

like image 853
Michael Chuprin Avatar asked Apr 30 '26 23:04

Michael Chuprin


1 Answers

Here is one of the possible solutions:

  1. Create an empty image object using: Image.new(mode, size, color)

  2. Modify the image object to contain the data from the "list"

  3. Save the image

E.g.:

new_img = Image.new("L", (NEW_X_SIZE, NEW_Y_SIZE), "white")
new_img.putdata(new_img_list)
new_img.save('out.tif')
like image 130
The Jonty Avatar answered May 03 '26 22:05

The Jonty



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!