Skip to content
Advertisement

Can’t duplicate .gif file in my folder. Will only give the first frame of the gif for each duplicate that is created

from PIL import Image

#Load the image
img = Image.open('1.gif')

for a in range(1,10):
    img.save(''+str(a)+'.gif')

Advertisement

Answer

If you just want to make 9 identical copies of image.gif, called copy-1.gif through copy-9.gif you don’t need PIL/Pillow at all – you are just copying a file and the fact it contains an image is irrelevant, so you can simply use shutil.copy:

import shutil

# Make 9 copies of "image.gif"
for i in range(1,10):
    shutil.copy('image.gif', f'copy-{i}.gif')

If you list the results:

-rw-r--r--@    1 mark  staff       2421 22 Jul 19:43 image.gif
-rw-r--r--@    1 mark  staff       2421 22 Jul 19:43 copy-1.gif
-rw-r--r--@    1 mark  staff       2421 22 Jul 19:43 copy-2.gif
-rw-r--r--@    1 mark  staff       2421 22 Jul 19:43 copy-3.gif
-rw-r--r--@    1 mark  staff       2421 22 Jul 19:43 copy-4.gif
-rw-r--r--@    1 mark  staff       2421 22 Jul 19:43 copy-5.gif
-rw-r--r--@    1 mark  staff       2421 22 Jul 19:43 copy-6.gif
-rw-r--r--@    1 mark  staff       2421 22 Jul 19:43 copy-7.gif
-rw-r--r--@    1 mark  staff       2421 22 Jul 19:43 copy-8.gif
-rw-r--r--@    1 mark  staff       2421 22 Jul 19:43 copy-9.gif
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement