Improved file extension parsing algorithm

The old one was pretty terrible.  This one is much better - and less
code.
Fix suggested filename of duplicated images when original image had no extension

Fixes #62