-3

I have these:

pixels = [(255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0), (204, 204, 204, 255), (204, 204, 204, 255), (119, 119, 119, 255), (119, 119, 119, 255), (204, 204, 204, 255), (204, 204, 204, 255), (255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0)......]

It's a list with a lot of tuples and I want to convert it into an image.

I can't find any solution.

martineau
  • 119,623
  • 25
  • 170
  • 301
  • Because your image data is in a 1D list, it is impossible to convert this into a 2D representation if you don't have the expected rows and columns. There are many combinations of rows and columns that can fit the image data provided so this question isn't possible to answer. – rayryeng Apr 16 '18 at 21:13

2 Answers2

1

You can use the Python Imaging Library as an alternative, to convert your array to image:

from PIL import Image

pixels = [(255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0), (204, 204, 204, 255), (204, 204, 204, 255), (119, 119, 119, 255), (119, 119, 119, 255), (204, 204, 204, 255), (204, 204, 204, 255), (255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0)......]

#Sample values of width and height. Change them according to your needs.
size = (50,50)

fileName = "image.png"

image = Image("RGBA",size)
image.putdata(pixels)
image.save(fileName)
Vasilis G.
  • 7,556
  • 4
  • 19
  • 29
0

PyPNG. writes NumPy arrays to images.

png.from_array([[255, 0, 0, 255],
                [0, 255, 255, 0]], 'L').save("file.png")

will do it

Baedsch
  • 581
  • 5
  • 12