0

Are there any APIs or libraries I can use to create a .gif out of .jpgs and .pngs? I'm looking for one that will work with Python 3.

John Pham
  • 183
  • 2
  • 2
  • 6

2 Answers2

4

Try googling, there are a lot of answers for this question. Here are the top three when I looked

Programmatically generate video or animated GIF in Python?

Generating an animated GIF in Python

https://sukhbinder.wordpress.com/2014/03/19/gif-animation-in-python-in-3-steps/

Community
  • 1
  • 1
af3ld
  • 782
  • 8
  • 30
4

Here is something that I wrote a while ago. I couldn't find anything better when I wrote this in the last six months. Hopefully this can get you started. It uses ImageMagick found here!

import os, sys
import glob
dataDir = 'directory of image files' #must contain only image files
#change directory gif directory
os.chdir(dataDir)


#Create txt file for gif command
fileList = glob.glob('*') #star grabs everything, can change to *.png for only png files
fileList.sort()
#writes txt file
file = open('blob_fileList.txt', 'w')
for item in fileList:
    file.write("%s\n" % item)

file.close()


#verifies correct convert command is being used, then converts gif and png to new gif
os.system('SETLOCAL EnableDelayedExpansion')
os.system('SET IMCONV="C:\Program Files\ImageMagick-6.9.1-Q16\Convert"')
# The following line is where you can set delay of images (100)
os.system('%IMCONV% -delay 100 @fileList.txt theblob.gif')

New convert call

For whatever reason (I didn't look at differences), I no longer needed the set local and set command lines in the code. I needed it before because the convert command was not being used even with path set. When you use the new 7.. release of image magick. See new line of code to replace last three lines. Be sure to check box that ask to download legacy commands e.g convert when installing. Everything was converted to a single magick command, but I didnt want to relearn the new conventions.

os.system('convert -delay 50 @fileList.txt animated.gif')
Almidas
  • 379
  • 2
  • 6
  • 16