Skip to content

Commit 9e42b9f

Browse files
committed
ENH: Add helper to fetch images from URLs
1 parent 02fc6a1 commit 9e42b9f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

nibabel/filebasedimages.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,3 +574,13 @@ def to_bytes(self, **kwargs):
574574
file_map = self.make_file_map({'image': bio, 'header': bio})
575575
self.to_file_map(file_map, **kwargs)
576576
return bio.getvalue()
577+
578+
@classmethod
579+
def from_url(klass, url):
580+
""" Fetch image from remote location and construct an image
581+
582+
Requires the ``requests`` library to be installed.
583+
"""
584+
import requests
585+
res = requests.get(url)
586+
return klass.from_bytes(res.content)

0 commit comments

Comments
 (0)