2

I am trying to generate and save an image with a new name for each loop.Is this possible in python with a for loop?Or should I try a different approach?

For i in range(x,y)
 i=str(i)
 p= img(i).save(s+i+j,)
 i=int('i')
 i=i+1
Ka_Papa
  • 137
  • 9

1 Answers1

0
from PIL import Image

images = [...]

# create some images 

for i, image in enumerate(images):
    image.save('image_%03d.png' % i)
Szabolcs Dombi
  • 5,493
  • 3
  • 39
  • 71
  • I did not know that Image supports indexing – Ka_Papa Aug 02 '16 at 07:29
  • @GeorgeNostradamos You didn't know it, and you don't know it now. `img` is a list. Note the list notation `[...]` whereby Dombi meant that you get a list of 10 images. – vlad-ardelean Aug 02 '16 at 07:36
  • So what he wrote could easily be described like this (input my images inside a list and then just put an index). I understood that, it was clear, I mean he could just write it, not that I am not grateful that he gave me the code, what I don't understand is why are you explaining it to me when the code is talking by itself.Either way thanks to both of you for your time. P.S I did not mean to offend you, what so ever.So, sorry if you get offended. – Ka_Papa Aug 02 '16 at 07:51