fix skipping of images

- implement proper try/except blocks around calls that can fail
- skip existing images, don't overwrite
- sort images to process to make order stable (sometimes still not
	  deterministic though)
- add tests
minor code cleanup