check image exists before getting id