[Python] 4 lines of code to synthesize multiple pictures into gif animation (imageio)

Dependent modules

pip install imageio

Test sample

3Zhang 600×400black and white 1.jpgpicture: , 2.jpgand3.jpg

Insert picture description here
Insert picture description here
Insert picture description here

Synthetic result

Insert picture description here

Sample code

import imageio
with imageio.get_writer(uri='test.gif', mode='I', fps=1) as writer:
    for i in range(3):
        writer.append_data(imageio.imread(f'{i+1}.jpg'))

Parameter Description

  • uri: gifThe name of the synthesized GIF can be changed at will.
  • mode:Operation mode, which Imeans multiple pictures, no need to change.
  • fps: Frame rate, that is, the number of frames transmitted per second, the larger the value, the greater gifthe playback speed of the animation.

Code explanation

The names of the three pictures are respectively 1.jpg, 2.jpgand 3.jpg, here I use a forloop to sequentially read and write them into the animation test.giffile for synthesis.

Citation reference

https://imageio.readthedocs.io/en/stable/examples.html

Guess you like

Origin blog.csdn.net/qq_42951560/article/details/115056163