Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust remove #9

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ boarbot/
*localCreds.json

*png

*.env
*.json
*.csv
*.o
Expand Down
81 changes: 4 additions & 77 deletions commands/misc.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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.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)

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")
Expand All @@ -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")
base.save(f"images/{username}.png")
2 changes: 1 addition & 1 deletion localCreds.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"host" : "localhost",
"database": "postgres",
"user": "postgres",
"password" : "",
"password" : "ola",
"port" : 5432

}
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
psycopg2
python-dateutil
requests
pillow
remove_boar