Python 使用images2gif生成gif
我正在从一些.png图片生成一个带有images2gif的gif。我正在使用以下脚本:Python 使用images2gif生成gif,python,gif,animated-gif,Python,Gif,Animated Gif,我正在从一些.png图片生成一个带有images2gif的gif。我正在使用以下脚本: __author__ = 'Robert' from images2gif import writeGif from PIL import Image import os file_names = sorted((fn for fn in os.listdir('/home/manager/Desktop/sf_linux_shared/project/prueba') if fn.endswith
__author__ = 'Robert'
from images2gif import writeGif
from PIL import Image
import os
file_names = sorted((fn for fn in os.listdir('/home/manager/Desktop/sf_linux_shared/project/prueba') if fn.endswith('.png')))
#['animationframa.png', 'animationframb.png', ...] "
images = [Image.open(fn) for fn in file_names]
size = (150,150)
for im in images:
im.thumbnail(size, Image.ANTIALIAS)
print writeGif.__doc__
filename = "my_gif.GIF"
writeGif(filename, images, duration=0.2)
但是,我有以下错误:
IOError:[Errno 2]没有这样的文件或目录:“cosa.png”
cosa.png是我想要创建gif的图片之一。问题似乎在于:
images = [Image.open(fn) for fn in file_names]
但是如果filename
不是文件名,我就无法检测到它在当前工作目录中的查找
绝对路径。当前工作目录是运行脚本的目录
使用os.chdir
更改工作目录,或将所有文件名设置为绝对:
WORKDIR = '/home/manager/Desktop/sf_linux_shared/project/prueba'
file_names = sorted((os.path.join(WORDIR, fn)
for fn in os.listdir(WORKDIR) if fn.endswith('.png')))