Create helper function for image conversion