Catch PIL imread problems early and generate error message

This addresses problems seen in #1154 and #1091.