-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexaminer.py
32 lines (29 loc) · 883 Bytes
/
examiner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from PIL import Image
import sys
def examine(fname, maxpix):
im = Image.open(fname) # Can be many different formats.
pix = im.load()
x_size, y_size = im.size # Get the width and hight of the image for iterating over
print("X-axis size: " + str(x_size))
print("Y-axis size: " + str(y_size))
counter = 0
for x in range(x_size):
for y in range(y_size):
if str(counter) == maxpix:
return
try:
r, g, b, a = pix[x, y]
except:
r, g, b = pix[x, y]
a = 255
print("r: {}, g: {}, b: {}, a: {}".format(r, g, b, a))
counter += 1
def main():
try:
fname = sys.argv[1]
maxpix = sys.argv[2]
except:
print("USAGE: examiner.py <image_name> <pixels_to_examine>")
examine(fname, maxpix)
return
main()