@@ -1526,29 +1526,13 @@ def imread(fname, format=None):
15261526 ext = format
15271527 img_open = (
15281528 PIL .PngImagePlugin .PngImageFile if ext == 'png' else PIL .Image .open )
1529- if isinstance (fname , str ):
1530- parsed = parse .urlparse (fname )
1531- if len (parsed .scheme ) > 1 : # Pillow doesn't handle URLs directly.
1532- _api .warn_deprecated (
1533- "3.4" , message = "Directly reading images from URLs is "
1534- "deprecated since %(since)s and will no longer be supported "
1535- "%(removal)s. Please open the URL for reading and pass the "
1536- "result to Pillow, e.g. with "
1537- "``np.array(PIL.Image.open(urllib.request.urlopen(url)))``." )
1538- # hide imports to speed initial import on systems with slow linkers
1539- from urllib import request
1540- ssl_ctx = mpl ._get_ssl_context ()
1541- if ssl_ctx is None :
1542- _log .debug (
1543- "Could not get certifi ssl context, https may not work."
1544- )
1545- with request .urlopen (fname , context = ssl_ctx ) as response :
1546- import io
1547- try :
1548- response .seek (0 )
1549- except (AttributeError , io .UnsupportedOperation ):
1550- response = io .BytesIO (response .read ())
1551- return imread (response , format = ext )
1529+ if isinstance (fname , str ) and len (parse .urlparse (fname ).scheme ) > 1 :
1530+ # Pillow doesn't handle URLs directly.
1531+ raise ValueError (
1532+ "Please open the URL for reading and pass the "
1533+ "result to Pillow, e.g. with "
1534+ "``np.array(PIL.Image.open(urllib.request.urlopen(url)))``."
1535+ )
15521536 with img_open (fname ) as image :
15531537 return (_pil_png_to_float_array (image )
15541538 if isinstance (image , PIL .PngImagePlugin .PngImageFile ) else
0 commit comments