Skip to content

Commit

Permalink
Merge pull request ipython#1616 from Carreau/coreImage
Browse files Browse the repository at this point in the history
Make IPython.core.display.Image less notebook-centric

embed images by default when only given as Image('url'), as opposed to Image(url='url').
  • Loading branch information
minrk committed May 2, 2012
2 parents 3c557d3 + 7a4eea0 commit edf006b
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 8 deletions.
26 changes: 20 additions & 6 deletions IPython/core/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ class Image(DisplayObject):

_read_flags = 'rb'

def __init__(self, data=None, url=None, filename=None, format=u'png', embed=False):
def __init__(self, data=None, url=None, filename=None, format=u'png', embed=None):
"""Create a display an PNG/JPEG image given raw data.
When this object is returned by an expression or passed to the
Expand All @@ -441,10 +441,24 @@ def __init__(self, data=None, url=None, filename=None, format=u'png', embed=Fals
The format of the image data (png/jpeg/jpg). If a filename or URL is given
for format will be inferred from the filename extension.
embed : bool
Should the image data be embedded in the notebook using a data URI (True)
or be loaded using an <img> tag. Set this to True if you want the image
to be viewable later with no internet connection. If a filename is given
embed is always set to True.
Should the image data be embedded using a data URI (True) or be
loaded using an <img> tag. Set this to True if you want the image
to be viewable later with no internet connection in the notebook.
Default is `True`, unless the keyword argument `url` is set, then
default value is `False`.
Note that QtConsole is not able to display images if `embed` is set to `False`
Examples
--------
# embed implicitly True, works in qtconsole and notebook
Image('http://www.google.fr/images/srpr/logo3w.png')
# embed implicitly False, does not works in qtconsole but works in notebook if
# internet connection available
Image(url='http://www.google.fr/images/srpr/logo3w.png')
"""
if filename is not None:
ext = self._find_ext(filename)
Expand All @@ -460,7 +474,7 @@ def __init__(self, data=None, url=None, filename=None, format=u'png', embed=Fals
if ext == u'png':
format = u'png'
self.format = unicode(format).lower()
self.embed = True if filename is not None else embed
self.embed = embed if embed is not None else (url is None)
super(Image, self).__init__(data=data, url=url, filename=filename)

def reload(self):
Expand Down

0 comments on commit edf006b

Please sign in to comment.