sir-lancebot icon indicating copy to clipboard operation
sir-lancebot copied to clipboard

Flag background for prideavatar.

Open TheClonerx opened this issue 6 years ago • 3 comments

For transparent avatars, having the desired flag as the background would be better than just a black color.

TheClonerx avatar Jun 18 '19 15:06 TheClonerx

@TheClonerx can you provide some examples and a bit of clarification?

jodth07 avatar Jun 26 '19 12:06 jodth07

When an avatar has already an alpha channel, avatar.putalpha(mask), in the crop_avatar method, replaces it, so the original transparent pixels become black.

A solution would be preserving the original transparent pixels by extracting the alpha channel of the image and performing a logical and with the crop mask before applying it to the avatar (it would be necessary to import ImageChops module from PIL).

    @staticmethod
    def crop_avatar(avatar):
        """This crops the avatar into a circle."""
        alpha = avatar.split()[-1].convert("1")  # new line
        mask = Image.new("1", avatar.size, 0)  # mode changed to 1
        draw = ImageDraw.Draw(mask)
        draw.ellipse((0, 0) + avatar.size, fill=255)
        mask = ImageChops.logical_and(mask, alpha)  # new line
        avatar.putalpha(mask)
        return avatar

Current result: Current result Desired result: Desired result

alucebur avatar Aug 08 '19 10:08 alucebur

Greetings. Great idea y'all, I think this should be implemented.

(Sorry, 2 years late)

Xithrius avatar Mar 02 '21 06:03 Xithrius