Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make IPython.core.display.Image less notebook-centric #1616

Merged
merged 9 commits into from
May 2, 2012
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 20 additions & 6 deletions IPython/core/display.py
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