You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.1 KiB
53 lines
1.1 KiB
from PIL import Image, ImageOps
|
|
|
|
# [[0,0, rgb1],... [1,1, rgb2]] -> [[1,1, rgb1],...[0,0, rgb2]]
|
|
def flip(cords):
|
|
fliped = []
|
|
flips = len(cords)//2
|
|
|
|
# El from start and el from end
|
|
fl0 = 0 ; fl1 = len(cords)-1
|
|
|
|
for i in range(flips):
|
|
# Copy element and change cords to cords of end element
|
|
new_st = list(cords[fl0])
|
|
new_st[0] = cords[fl1][0]
|
|
new_st[1] = cords[fl1][1]
|
|
fliped.append(new_st)
|
|
|
|
# Copy and change cords to cords of start element
|
|
new_end = list(cords[fl1])
|
|
new_end[0] = cords[fl0][0]
|
|
new_end[1] = cords[fl0][1]
|
|
fliped.append(new_end)
|
|
|
|
fl0 += 1 ; fl1 -= 1
|
|
|
|
return fliped
|
|
|
|
# convert("example.png") // png/jpg/gif
|
|
def convert(filename, move = [0,0]):
|
|
im = Image.open(filename).convert('RGB')
|
|
# Fix mirror
|
|
im = ImageOps.mirror(im)
|
|
pxls=im.load()
|
|
w=im.size[0]
|
|
h=im.size[1]
|
|
|
|
ll = []
|
|
for x in range(w):
|
|
for y in range(h):
|
|
# [x,y, [r, g, b]]
|
|
rgb = pxls[x,y]
|
|
ll.append( [x,y, rgb[0], rgb[1], rgb[2] ] )
|
|
|
|
# Fix flip
|
|
fliped = flip(ll)
|
|
|
|
# Move [x,y] + move
|
|
moved = []
|
|
for i in fliped:
|
|
moved.append([i[0] + move[0], i[1] + move[1], i[2],i[3],i[4]])
|
|
|
|
return moved
|