slightly refactor the image publishing code