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
|
from tqdm import tqdm
|
||||||
|
|
||||||
def optimize(l):
|
def optimize(pxls, back):
|
||||||
back = input("Enter background color > ")
|
old_len = len(pxls)
|
||||||
new_l = []
|
|
||||||
for i in tqdm(l):
|
|
||||||
if i[2] == back:
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
new_l.append(i)
|
|
||||||
|
|
||||||
f = open("out.txt", "w")
|
new_pxls = []
|
||||||
f.write(str(new_l))
|
for i in tqdm(range(old_len)):
|
||||||
f.close()
|
el = pxls[i]
|
||||||
|
now_back = [el[2], el[3], el[4]]
|
||||||
|
|
||||||
print(f"Lenght before: {len(l)}")
|
if now_back != back:
|
||||||
print(f"Lenght after: {len(new_l)}")
|
new_pxls.append(pxls[i])
|
||||||
optimized = len(l)-len(new_l)
|
|
||||||
print(f"Optimized: {optimized} ( -{round(optimized/(len(l)/100))}% )")
|
print(f"Optimized {(old_len - len(new_pxls)) / old_len * 100 }%")
|
||||||
|
|
||||||
return new_l
|
return new_pxls
|
||||||
|
Loading…
Reference in new issue