Generate an animated GIF from a folder full of .jpg images.
You need:
- Python 3; I used 3.6.2 for development and testing.
- The imageio package. If you're using pip, install with
pip install imageio
. I worked with version 2.2.0.
Make a folder called images
in the same folder where this README is located. Fill this folder with the .jpg images you want to turn into an animation. Each image should be named with an integer that corresponds to its desired position in the GIF. In other words, the code will place 00.jpg
before 01.jpg
in the animation, and so on.
Open the file makegif.py
and check lines 7-10. You can change a few settings here:
outfile = 'output.gif'
tells the code to put the output GIF in the same folder as the code, and call it "output.gif".fps = 30
sets the animation speed to 30 frames per second. Feel free to change this.- The next two lines are used to crop the image.
xrange = range(500,1310)
tells the code to take only the pixel range from 500 to 1310 horizontally (0 corresponds to the left edge).yrange = range(360,1030)
crops the image to the vertical range 360-1030 (where 0 corresponds to the top edge). If you do not want to crop, set eitherxrange
oryrange
toNone
.
Once you are satisfied with the settings, run the following:
python makegif.py
You should see messages communicating the code's progress. GIF generation should take around 30-45 seconds for one thousand input images that are each 250kB large. The resulting GIF should be about 2MB in size, provided that only a small part of each frame changes during the animation.