LoginSignup
3
0

More than 5 years have passed since last update.

Python で PNG から 透過 GIF を生成する

Last updated at Posted at 2017-09-12

超Python初心者なんで、ハマり倒したのでメモ

from PIL import Image

im = Image.open("input.png")

alpha = im.split()[3]

im = im.convert('RGB').convert('P', palette=Image.ADAPTIVE, colors=255)

mask = Image.eval(alpha, lambda a: 255 if a <=128 else 0)

im.paste(255, mask)

im.save('export.gif', transparency=255)

細かい部分で何しているかわかってないですが、自分と同じことで時間を使ってしまう人が減るように・・

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0