Added image filesize validation and some refactoring

What's the deal with `(\.|\/)`? That would seem to match either a dot or a forward slash before the file extension.