File: exrandom.py

package info (click to toggle)
pypng 0.20231004.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 724 kB
  • sloc: python: 4,818; sh: 230; makefile: 19
file content (20 lines) | stat: -rw-r--r-- 453 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# An example program that create a random 64×64 RGB PNG file.
# Inspired by https://github.com/drj11/pypng/issues/120
import random

import png

width = 64
height = 64

# values per row
vpr = 3 * width

# Create a 2D matrix, a sequence of rows. Each row has vpr values.
m = [[0] * vpr for y_ in range(height)]

for y in range(len(m)):
    for x in range(len(m[y])):
        m[y][x] = random.randint(0, 255)

png.from_array(m, "RGB").save("random.png")