JavaScript
x
8
1
from PIL import Image
2
3
#Load the image
4
img = Image.open('1.gif')
5
6
for a in range(1,10):
7
img.save(''+str(a)+'.gif')
8
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
:
JavaScript
1
6
1
import shutil
2
3
# Make 9 copies of "image.gif"
4
for i in range(1,10):
5
shutil.copy('image.gif', f'copy-{i}.gif')
6
If you list the results:
JavaScript
1
11
11
1
-rw-r--r--@ 1 mark staff 2421 22 Jul 19:43 image.gif
2
-rw-r--r--@ 1 mark staff 2421 22 Jul 19:43 copy-1.gif
3
-rw-r--r--@ 1 mark staff 2421 22 Jul 19:43 copy-2.gif
4
-rw-r--r--@ 1 mark staff 2421 22 Jul 19:43 copy-3.gif
5
-rw-r--r--@ 1 mark staff 2421 22 Jul 19:43 copy-4.gif
6
-rw-r--r--@ 1 mark staff 2421 22 Jul 19:43 copy-5.gif
7
-rw-r--r--@ 1 mark staff 2421 22 Jul 19:43 copy-6.gif
8
-rw-r--r--@ 1 mark staff 2421 22 Jul 19:43 copy-7.gif
9
-rw-r--r--@ 1 mark staff 2421 22 Jul 19:43 copy-8.gif
10
-rw-r--r--@ 1 mark staff 2421 22 Jul 19:43 copy-9.gif
11