mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-01 16:37:16 +08:00
Merge pull request #1162 from blink1073/improve-pil-error-messages
Catch PIL imread problems early and generate error message
This commit is contained in:
@@ -29,7 +29,14 @@ def imread(fname, dtype=None):
|
||||
|
||||
"""
|
||||
im = Image.open(fname)
|
||||
return pil_to_ndarray(im, dtype)
|
||||
try:
|
||||
# this will raise an IOError if the file is not readable
|
||||
im.getdata()[0]
|
||||
except IOError:
|
||||
site = "http://pillow.readthedocs.org/en/latest/installation.html#external-libraries"
|
||||
raise ValueError('Could not load "%s"\nPlease see documentation at: %s' % (fname, site))
|
||||
else:
|
||||
return pil_to_ndarray(im, dtype)
|
||||
|
||||
|
||||
def pil_to_ndarray(im, dtype=None):
|
||||
|
||||
Reference in New Issue
Block a user