It's time to make the rest of the script become part of the loop as well.

Where you create file, replace "img1.png" with filename and indent the line with all the other lines that follow.