You could do some work on the script code so it selects all images on a directory (let's say /images) and loop through all of them.
the php function you're interested in is readdir()
now, since your example shows that images are numbered sequentially (1.jpg, 2.jpg...... etc) there is a solution which is a bit rougher but still works if you don't want to mess with readdir (you still have to do a bit of coding though)
note the first and last numbers on the set of images (let's say they begin at 1.jpg and end at 100.jpg, so you write down 1 and 100)
have the script run within a loop (I suggest you use For) with initial value 1 and upper limit 100. on each instance, have variable fname take the value x."jpg" (x will cycle from 1 to 100 or whatever upper limit you set) so on each pass the script runs with a different image number
I don't know if I made myself clear enough, let me know if you could make any sense of my mumbo-jumbo