CONTRIB-4909  More robust certificate_scan_image_dir function

Hello Mark, here is the pull request for the certificate_image_dir function.