Skip to content

Commit

Permalink
rua 透明背景
Browse files Browse the repository at this point in the history
  • Loading branch information
LHXnois authored Feb 27, 2021
1 parent 17c2018 commit d49f475
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions shebot/rua/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ def generate_gif(frame_dir: str, avatar: Image.Image) -> Image.Image:
avatar_pos = [(50,150), (28,195), (5,217), (5,195), (50,128)]
imgs = []
for i in range(5):
im = Image.new(mode='RGBA', size=(600, 600), color='white')
im = Image.new(mode='RGBA', size=(600, 600))
hand = Image.open(path.join(frame_dir, f'hand-{i+1}.png'))
hand = hand.convert('RGBA')
avatar = get_circle_avatar(avatar, 350)
avatar = avatar.resize(avatar_size[i])
im.paste(avatar, avatar_pos[i], mask=avatar.split()[3])
im.paste(hand, mask=hand.split()[3])
mask = im.split()[3]
mask = Image.eval(mask, lambda a: 255 if a <= 50 else 0)
im = im.convert('RGB').convert('P', palette=Image.ADAPTIVE, colors=255)
im.paste(255, mask)
imgs.append(im)
out_path = path.join(frame_dir, 'output.gif')
imgs[0].save(fp=out_path, save_all=True, append_images=imgs, duration=25, loop=0, quality=80)
imgs[0].save(fp=out_path, save_all=True, append_images=imgs,
duration=25, loop=0, quality=80, transparency=255, disposal=3)
return out_path

0 comments on commit d49f475

Please sign in to comment.