Skip to content

Commit 2cdb576

Browse files
committed
ENH: Add helper to fetch images from URLs
1 parent 126a9a9 commit 2cdb576

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
@@ -571,3 +571,13 @@ def to_bytes(self):
571571
file_map = self.make_file_map({'image': bio, 'header': bio})
572572
self.to_file_map(file_map)
573573
return bio.getvalue()
574+
575+
@classmethod
576+
def from_url(klass, url):
577+
""" Fetch image from remote location and construct an image
578+
579+
Requires the ``requests`` library to be installed.
580+
"""
581+
import requests
582+
res = requests.get(url)
583+
return klass.from_bytes(res.content)

0 commit comments

Comments
 (0)