Fix flip-bug, now convert normally image.

main
none 1 year ago
parent a561b1a08b
commit 161e8cb728

Binary file not shown.

Before

Width:  |  Height:  |  Size: 157 KiB

After

Width:  |  Height:  |  Size: 9.9 KiB

@ -1,5 +1,30 @@
from PIL import Image from PIL import Image
# [[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 # convert("example.png") // png/jpg/gif
def convert(filename, move = [0,0]): def convert(filename, move = [0,0]):
im = Image.open(filename).convert('RGB') im = Image.open(filename).convert('RGB')
@ -12,6 +37,14 @@ def convert(filename, move = [0,0]):
for y in range(h): for y in range(h):
# [x,y, [r, g, b]] # [x,y, [r, g, b]]
rgb = pxls[x,y] rgb = pxls[x,y]
ll.append( [x + move[0], y + move[1], rgb[0], rgb[1], rgb[2] ] ) 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 ll return moved

Loading…
Cancel
Save