search
LoginSignup
13
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

posted at

Python PillowでPNGからGIFを作る

  • 同ディレクトリ内にあるPNGからGIFを生成する
  • Python 3.6.5

ディレクトリ構成

gif-test
  ├── main.py
  ├── requirements.txt
  ├── 001.png
  ├── 002.png
  └── 003.png

ファイルの内容

  • requirements.txt

    requirements.txt
    Pillow==5.2.0
    
  • main.py

    main.py
    from PIL import Image
    import glob
    
    files = sorted(glob.glob('./*.png'))
    images = list(map(lambda file: Image.open(file), files))
    
    images[0].save('out.gif', save_all=True, append_images=images[1:], duration=400, loop=0)
    
  • *.png

    • 適当なファイルを

参考

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
What you can do with signing up
13
Help us understand the problem. What are the problem?