improved checking if an image file exists