Refactor creation of image metadata