Improved filetype check to use imghdr