parent
4373dab299
commit
a561b1a08b
After Width: | Height: | Size: 157 KiB |
@ -0,0 +1,17 @@
|
||||
from PIL import Image
|
||||
|
||||
# convert("example.png") // png/jpg/gif
|
||||
def convert(filename, move = [0,0]):
|
||||
im = Image.open(filename).convert('RGB')
|
||||
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 + move[0], y + move[1], rgb[0], rgb[1], rgb[2] ] )
|
||||
|
||||
return ll
|
@ -1,21 +1,16 @@
|
||||
from tqdm import tqdm
|
||||
|
||||
def optimize(l):
|
||||
back = input("Enter background color > ")
|
||||
new_l = []
|
||||
for i in tqdm(l):
|
||||
if i[2] == back:
|
||||
continue
|
||||
else:
|
||||
new_l.append(i)
|
||||
def optimize(pxls, back):
|
||||
old_len = len(pxls)
|
||||
|
||||
f = open("out.txt", "w")
|
||||
f.write(str(new_l))
|
||||
f.close()
|
||||
new_pxls = []
|
||||
for i in tqdm(range(old_len)):
|
||||
el = pxls[i]
|
||||
now_back = [el[2], el[3], el[4]]
|
||||
|
||||
print(f"Lenght before: {len(l)}")
|
||||
print(f"Lenght after: {len(new_l)}")
|
||||
optimized = len(l)-len(new_l)
|
||||
print(f"Optimized: {optimized} ( -{round(optimized/(len(l)/100))}% )")
|
||||
|
||||
return new_l
|
||||
if now_back != back:
|
||||
new_pxls.append(pxls[i])
|
||||
|
||||
print(f"Optimized {(old_len - len(new_pxls)) / old_len * 100 }%")
|
||||
|
||||
return new_pxls
|
||||
|
Loading…
Reference in new issue