1

I need to remove these black borders, that appear after rotating pfp picture:

result after rotation

yesno = Image.open('images\yesno.jpg')

asset = member.avatar_url_as(size = 128)
data = BytesIO(await asset.read())
pfp = Image.open(data)
pfp = pfp.resize((100,100))
pfp = pfp.rotate(-50)

yesno.paste(pfp, (138,408))
yesno.save('proba.jpg')

I'm tried to make transparency masks to remove these black borders, but this is worked only on sad pepe profile picture, on others it wrote 'bad transparency mask'. Also I tried some others way like composite function from pillow but that didn't actually helped me.

This would be awesome if there exists some generic way for my problem to resolve.

martineau
  • 119,623
  • 25
  • 170
  • 301
fralorange
  • 31
  • 3
  • The [`Image.rotate()`](https://pillow.readthedocs.io/en/latest/reference/Image.html#PIL.Image.Image.rotate) function accepts an optional _`fillcolor`_ argument. If you can convert the image you want to rotate into the RGBA colorspace, it seems like you ought to be able specify a `fillcolor` that was completely transparent. – martineau Feb 12 '21 at 17:54
  • 1
    https://stackoverflow.com/questions/56765467/is-there-another-way-to-fill-the-area-outside-a-rotated-image-with-white-color – pippo1980 Feb 12 '21 at 17:55

1 Answers1

0
yesno = Image.open('images\yesno.jpg').convert('RGBA')
#
asset = member.avatar_url_as(size = 128)
data = BytesIO(await asset.read())
pfp = Image.open(data).convert('RGBA')
pfp = pfp.resize((100,100))
pfp = pfp.rotate(-50,fillcolor = 0)
#
yesno.paste(pfp, (138,408),pfp)
#
yesno.save('proba.png')

I figured out how to do it, here's the code example which worked for me, if someone needs

fralorange
  • 31
  • 3