separating image-type detection to separate function /cc @drsnyder