Added code to convert image to a supported format before returning it, if necessary