Tidied up the extension checking and made it handle image derivatives.