Reputation: 17
code:
avatar = Image.open('temp_avatar.png').convert('RGBA')
color = (255,255,255,0)
mask = Image.new("L", avatar.size, 0)
mask_draw = ImageDraw.Draw(mask)
size = avatar.width
mask_draw.polygon([~irrelevant~], fill=255)
avatar_finale = avatar.copy()
avatar_finale.putalpha(mask_draw)
avatar_finale.save('temp_avatar.png')
error message:
File "C:\Users\amit2\source\repos\LAKRIS bot\LAKRIS bot\cogs\rank.py", line 42, in processing
avatar_finale.putalpha(mask_draw)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\PIL\Image.py", line 1654, in putalpha
alpha.load()
AttributeError: 'ImageDraw' object has no attribute 'load'
i dont really know what the problem is, i ran a very similar code with .putalpha() and it worked.
Upvotes: 1
Views: 4067
Reputation: 207758
Your penultimate line is wrong - it is trying to put the Draw object of the mask, rather than mask itself, itself into the alpha channel.
So, replace:
avatar_finale.putalpha(mask_draw)
with:
avatar_finale.putalpha(mask)
Upvotes: 2