New image draw and optimizer 🎉

main
none 1 year ago
parent 4373dab299
commit a561b1a08b

@ -77,3 +77,9 @@ print(ccheck(cfill(0,0, 34,34)))
# Use extras, draw 1/2 random square 100x100 on 0,0
from bot_extras import *
draw(pas2( rand(0,0, 100,100) ))
# Draw image (flipped (BUG) )
from im_convert import *
image = convert("example.png", [600,0])
from remove_back import *
draw( optimize(image, [255,255,255]) ) # Remove white background and draw

Binary file not shown.

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…
Cancel
Save