Use imghdr instead of mimetype to get image type.