48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
from PIL import Image
|
|
import math
|
|
import argparse
|
|
|
|
parser = argparse.ArgumentParser(
|
|
prog = 'Image Edit Script',
|
|
description = 'Manipulate or extract information from an image file',
|
|
epilog = '')
|
|
|
|
parser.add_argument('filename') # positional argument
|
|
parser.add_argument('-o', '--output') # option that takes a value
|
|
parser.add_argument('-v', '--verbose', action='store_true') # on/off flag
|
|
|
|
args = parser.parse_args()
|
|
print(args.filename, args.output, args.verbose)
|
|
|
|
|
|
im = Image.open(args.filename) # Can be many different formats.
|
|
pix = im.load()
|
|
print(im.size) # Get the width and hight of the image for iterating over
|
|
print(pix[10,10]) # Get the RGBA Value of the a pixel of an image
|
|
|
|
|
|
|
|
def calculateDistance(x1,y1,x2,y2):
|
|
dist = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
|
|
return dist
|
|
|
|
with open('result.txt', 'w') as f:
|
|
for x in range(im.size[0]):
|
|
f.write("backBuffer[")
|
|
f.write(str(x))
|
|
f.write("]=0b")
|
|
for y in range(im.size[1]):
|
|
c = pix[x,y] #get pixel
|
|
if (c[0]>127):
|
|
f.write("1")
|
|
else:
|
|
f.write("0")
|
|
|
|
|
|
f.write(";")
|
|
f.write('\r\n')
|
|
|
|
|
|
|
|
|