Moved image conversion code to only be called when needed.