Check existence of images before going foreach