#🔒 Transparency error (Pillow)

6 messages · Page 1 of 1 (latest)

robust shore
#

I cant paste a transparent image without making the ones behind it also transparent, is there any way to do this? Im probably just making a mistake in the way I put it...

lethal coralBOT
#

@robust shore

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

robust shore
#

This is my code:

@tree.command(guild=discord.Object(id=id_do_servidor), name='documento', description='Cria um documento.')
@app_commands.describe(genero='Genero')
@app_commands.choices(genero=[
    app_commands.Choice(name='Masculino', value=1),
    app_commands.Choice(name='Feminino', value=2),
    app_commands.Choice(name='Furry', value=3),
    app_commands.Choice(name='N/O', value=4),
])
async def criardocumento(interaction: discord.Interaction, nome: str, nasc: str, genero: app_commands.Choice[int], nick: str, documento: str, foto_cidadao: discord.Attachment):
    genero_str = None

    if genero.value == 1:
       genero_str = "masculino"

    if genero.value == 2:
       genero_str = "feminino"

    if genero.value == 3:
       genero_str = "furry"

    if genero.value == 4:
       genero_str = "n/o"

    foto_cidadao_bytes = await foto_cidadao.read()

    foto_cidadao_bytes_io = io.BytesIO(foto_cidadao_bytes)

    foto = Image.open(foto_cidadao_bytes_io)

    imagem = Image.open("background.png")
    nova_largura = 1644
    nova_altura = 925
    foto = foto.resize((nova_largura, nova_altura))
    nova_imagem = Image.new("RGBA", imagem.size)
    nova_imagem.paste(imagem, (0, 0))
    coordenadas_foto = (-630, -200)
    foto_documento = Image.open("documento.png")
    filtro = Image.open("filtro.png")
    nova_imagem.paste(foto, coordenadas_foto, mask=foto)
    nova_imagem.paste(filtro, (0, 0), mask=filtro.convert("RGBA"))
    nova_imagem.paste(foto_documento, (0, 0), mask=foto_documento)

    documento_formatado = documento
    if documento.isdigit() and len(documento) >= 2:
        documento = documento.zfill(6)
        documento_formatado = f"{documento[:-2]}-{documento[-2:]}"

    textos = {
        "Nome": nome.upper(),
        "Nasc": nasc.upper(),
        "Genero": genero_str.upper(),
        "Nick": nick.upper(),
        "Documento": documento_formatado.upper(),
        "Hashtag": "#76.415.81.0",
        "Marcadagaua": "//0",
        "Marcadagaua2": documento.upper()
    }

    fonte_padrao = ImageFont.truetype("5mikropix.ttf", 45)
    fonte_novo1 = ImageFont.truetype("5mikropix.ttf", 45)
    fonte_novo2 = ImageFont.truetype("5mikropix.ttf", 32)

    desenho = ImageDraw.Draw(nova_imagem)

    coordenadas = {
        "Nome": (40, 35),
        "Nasc": (515, 105),
        "Genero": (515, 195),
        "Nick": (515, 285),
        "Documento": (299, 480),
        "Hashtag": (40, 480),
        "Marcadagaua": (783, 467),
        "Marcadagaua2": (852, 467)
    }

    for chave, valor in textos.items():
        if chave == "Hashtag":
            fonte = fonte_novo1
        elif chave == "Marcadagaua":
            fonte = fonte_novo2
        elif chave == "Marcadagaua2":
            fonte = fonte_novo2
        else:
            fonte = fonte_padrao
        desenho.text(coordenadas[chave], valor, fill="black", font=fonte)

    image_bytes = BytesIO()
    nova_imagem.save(image_bytes, format='PNG')
    image_bytes.seek(0)

    await interaction.channel.send(file=discord.File(image_bytes, 'documento.png'))
robust shore
lethal coralBOT
#

@robust shore

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.