I'm trying to make GIF from multiple image files, following this thread.
Kris's answer works perfectly when I open a physical file from a directory using Image.open()
and then append the list to make a GIF.
imgs = [Image.open(f) for f in os.listdir(os.getcwd())]
imgs[0].save('{}.gif'.format(img_filename),
format='GIF',
append_images=imgs[1:],
save_all=True,
duration=args.duration,
loop=0)
This works fine and the output GIF is infact animated. I noticed that the list glitched_imgs
consists of PIL.PngImagePlugin.PngImageFile
objects in this case.
However whenever I try to use an Image
object returned from a function, The GIF produced is completely static.
imgs = [get_randomized_image() for _ in range(args.frames)]
imgs[0].save('{}.gif'.format(img_filename),
format='GIF',
append_images=imgs[1:],
save_all=True,
duration=args.duration,
loop=0)
Where get_randomized_image()
returns a randomized Image
object, specifically from a numpy
array.
# Inside `get_glitched_image()`
return Image.fromarray(outputarr, img_mode)
I want to directly make a GIF with a list of objects returned from this function, how can I achieve this?
Note: The files I open in the first (working) method, are the files I saved prior using get_randomized_images()
so I can assure you they are exactly the same.