Advertisement
mmenegali

Write a PNG file in Python

Jun 3rd, 2020
1,213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. # Source: https://stackoverflow.com/questions/8554282/creating-a-png-file-in-python
  2.  
  3. import png
  4.  
  5. width = 255
  6. height = 255
  7. img = []
  8. for y in range(height):
  9.     row = ()
  10.     for x in range(width):
  11.         row = row + (x, max(0, 255 - x - y), y)
  12.     img.append(row)
  13. with open('gradient.png', 'wb') as f:
  14.     w = png.Writer(width, height, greyscale=False)
  15.     w.write(f, img)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement