From 1e3fc31b499fdd68847dbddd565ba9dff356de70 Mon Sep 17 00:00:00 2001 From: Torquato <30443527+trqt@users.noreply.github.com> Date: Fri, 10 Sep 2021 11:42:19 -0300 Subject: [PATCH 1/4] Now Remove uses an external package --- .gitignore | 2 +- commands/misc.py | 83 +++--------------------------------------------- requirements.txt | 2 +- 3 files changed, 7 insertions(+), 80 deletions(-) diff --git a/.gitignore b/.gitignore index 7f6a3f3..263e538 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ boarbot/ *localCreds.json *png - +*.env *.json *.csv *.o diff --git a/commands/misc.py b/commands/misc.py index e09dd92..1f6c5dc 100644 --- a/commands/misc.py +++ b/commands/misc.py @@ -1,7 +1,7 @@ -from PIL import Image from requests import get from datetime import datetime import discord +import remove_boar async def Boar(message): @@ -12,7 +12,7 @@ async def Capital(message): async def Ctest(message): import ctypes - test = ctypes.CDLL("libtest.so") + test = ctypes.cdll.LoadLibrary('./c/test.so') test.disc_test.restype = ctypes.c_char_p a = test.disc_test().decode() @@ -42,87 +42,14 @@ async def BackgroundRemover(message): await message.channel.send("Processando...") r_command = message.content.split() - cor_esperada = (255, 255, 255, 255) - cor_alvo = (255, 255, 255, 0) - await attachment.save("images/tmp.png") - img = Image.open("images/tmp.png").convert("RGBA") - - pixels = img.load() - - if len(r_command) > 4: - print(r_command) - cor_esperada = (int(r_command[2]), int(r_command[3]), int(r_command[4]), 255) - else: - cor_esperada = img.getpixel((0,0)) - - cor_alvo = (0,0,0,0) - print(cor_esperada) - print(cor_alvo) - #cor_alvo = (255, 255, 255, 255) - - imgX, imgY = img.size - imgX, imgY = imgX-1, imgY-1 - - checar = set() - - for A in range(imgX+1): - - if pixels[A, 0] == cor_esperada: - checar.add((A, 0)) - - if pixels[A, imgY] == cor_esperada: - checar.add((A, imgY)) - - for A in range(imgY+1): - - if pixels[0, A] == cor_esperada: - checar.add((0, A)) - - if pixels[imgX, A] == cor_esperada: - checar.add((imgX, A)) - - while len(checar) > 0: - - px = checar.pop() - - if pixels[px[0], px[1]] == cor_alvo: - checar.pop(0) - continue - - checar.update([A for A in GetSides(px, imgX, imgY) if pixels[A[0], A[1]] == cor_esperada]) - - - pixels[px[0], px[1]] = cor_alvo - - img.save("images/saida.png") - + remove_boar.backgroundremover("images/tmp.png") with open("images/saida.png", "rb") as fh: f = discord.File(fh, filename="images/saida.png") await message.channel.send(file=f) - - else: + else: await message.channel.send("Por favor, mande uma imagem.") - -def GetSides(pos:tuple, tamX:int, tamY:int): - - output = [] - - if ((pos[0] - 1) >= 0 and (pos[0] - 1) <= tamX): - output.append((pos[0] - 1, pos[1])) - - if ((pos[0] + 1) >= 0 and (pos[0] + 1) <= tamX): - output.append((pos[0] + 1, pos[1])) - - if ((pos[1] - 1) >= 0 and (pos[1] - 1) <= tamY): - output.append((pos[0], pos[1] - 1)) - - if ((pos[1] + 1) >= 0 and (pos[1] + 1) <= tamY): - output.append((pos[0], pos[1] + 1)) - - return output - def DownloadImage(url:str): image = get(url).content file = open("images/tmp.png","wb") @@ -133,4 +60,4 @@ def WelcomeImage(username:str,image:str,server:int): base = Image.open(f"images/back{server}.png") user = Image.open("images/tmp.png").resize((128,128)) base.paste(user,(20,348)) - base.save(f"images/{username}.png") \ No newline at end of file + base.save(f"images/{username}.png") diff --git a/requirements.txt b/requirements.txt index d20b079..8e24038 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ psycopg2 python-dateutil requests -pillow +remove_boar From ac43cf99cd717e1506e6a1b58ea09d7be3b6dffb Mon Sep 17 00:00:00 2001 From: Torquato <30443527+trqt@users.noreply.github.com> Date: Fri, 10 Sep 2021 11:45:25 -0300 Subject: [PATCH 2/4] Grab libtest.so from global folder --- commands/misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/misc.py b/commands/misc.py index 1f6c5dc..9d46767 100644 --- a/commands/misc.py +++ b/commands/misc.py @@ -12,7 +12,7 @@ async def Capital(message): async def Ctest(message): import ctypes - test = ctypes.cdll.LoadLibrary('./c/test.so') + test = ctypes.CDLL("libtest.so") test.disc_test.restype = ctypes.c_char_p a = test.disc_test().decode() From 1f880d8e7052c60b6794b9772742f543224b3352 Mon Sep 17 00:00:00 2001 From: Torquato <30443527+trqt@users.noreply.github.com> Date: Tue, 21 Sep 2021 19:11:58 -0300 Subject: [PATCH 3/4] Fixed background_remover name --- commands/misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/misc.py b/commands/misc.py index 9d46767..c8ba853 100644 --- a/commands/misc.py +++ b/commands/misc.py @@ -43,7 +43,7 @@ async def BackgroundRemover(message): r_command = message.content.split() await attachment.save("images/tmp.png") - remove_boar.backgroundremover("images/tmp.png") + remove_boar.background_remover("images/tmp.png") with open("images/saida.png", "rb") as fh: f = discord.File(fh, filename="images/saida.png") await message.channel.send(file=f) From eb02a876654be5ec5c8d0c1b46be18c018a8c2f9 Mon Sep 17 00:00:00 2001 From: Torquato <30443527+trqt@users.noreply.github.com> Date: Thu, 30 Sep 2021 19:30:48 -0300 Subject: [PATCH 4/4] fix: background_remover params --- commands/misc.py | 2 +- localCreds.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/misc.py b/commands/misc.py index c8ba853..acc4e83 100644 --- a/commands/misc.py +++ b/commands/misc.py @@ -43,7 +43,7 @@ async def BackgroundRemover(message): r_command = message.content.split() await attachment.save("images/tmp.png") - remove_boar.background_remover("images/tmp.png") + remove_boar.background_remover("images/tmp.png", "images/saida.png") with open("images/saida.png", "rb") as fh: f = discord.File(fh, filename="images/saida.png") await message.channel.send(file=f) diff --git a/localCreds.json b/localCreds.json index 592d64d..57d8680 100644 --- a/localCreds.json +++ b/localCreds.json @@ -2,7 +2,7 @@ "host" : "localhost", "database": "postgres", "user": "postgres", - "password" : "", + "password" : "ola", "port" : 5432 }