diff --git a/bot.py b/bot.py index 34ed5fa..4a5982f 100644 --- a/bot.py +++ b/bot.py @@ -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 diff --git a/example.png b/example.png new file mode 100644 index 0000000..435a3b3 Binary files /dev/null and b/example.png differ diff --git a/im_convert.py b/im_convert.py new file mode 100644 index 0000000..0e9fdbd --- /dev/null +++ b/im_convert.py @@ -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 diff --git a/remove_back.py b/remove_back.py index 466150d..5163da4 100644 --- a/remove_back.py +++ b/remove_back.py @@ -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