Added check if a directory exist before saving images.