fix #309

this is a very naive patch for #309.  

determining the format of a file by its extension is a very fragile approach, specially for remote images. 
For example, this is a valid JPEG image 
https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTgEmgnOC8Q_efV74QG4IizYVycmOz2f23yQbYwtmYAv4XqH9zEzA but would fail checking by its "extension" 

 a better way should be read the file and check it via [imghdr](https://docs.python.org/2/library/imghdr.html) from the python stdlib