More than likely you are going to need to use a database or text file to store the amount of hits of each image.
You should check out some of the image packages on hotscripts.com
As stated before these are really simple to write. I could do a custom one if you can't find yourself exactly what your looking for, shoot me an email.