Repository: ipython/ipython

Issue:
Display Image in Qtconsole
hi, 

playing with `notebook_00` code in qtconsole I saw that :

```
from IPython.core.display import *
Image('http://python.org/images/python-logo.gif')
```

Does not display the image in qtconsole
It seems that it works by setting `embed=True` as a kwarg, but the docstring state that (emphase mine):

```
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**.
```

Which don't give any clue as wether `embed` is needed for other frontend than notebook.
Moreover 'if a filename' seem to mean that if the (first) argument given to `Image` is a filename, the embed is automaticaly  set to true, whereas the code set `embed` to `True` if and only if the `filename **kwarg**` is not `None`.

I suggest setting embed to True after `super` as been initiated if either `self.filename` or `self.url` are not `None` to be able to display the Image in QtConsole by just dooing `Image(url or filename)`. Unless of course there is a good reason not to...

Display Image in Qtconsole
hi, 

playing with `notebook_00` code in qtconsole I saw that :

```
from IPython.core.display import *
Image('http://python.org/images/python-logo.gif')
```

Does not display the image in qtconsole
It seems that it works by setting `embed=True` as a kwarg, but the docstring state that (emphase mine):

```
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**.
```

Which don't give any clue as wether `embed` is needed for other frontend than notebook.
Moreover 'if a filename' seem to mean that if the (first) argument given to `Image` is a filename, the embed is automaticaly  set to true, whereas the code set `embed` to `True` if and only if the `filename **kwarg**` is not `None`.

I suggest setting embed to True after `super` as been initiated if either `self.filename` or `self.url` are not `None` to be able to display the Image in QtConsole by just dooing `Image(url or filename)`. Unless of course there is a good reason not to...



Discussion:
> Unless of course there is a good reason not to...

embed _should_ be False if a url is given, because that means the display data need only be `<img src="url"/>`, rather than including base64-encoded data.   This is a highly Notebook-centric behavior, as the QtConsole does not support non-embedded images at all, but it is _so much_ better in the notebook, that I think it's still the right choice.

Another solution would be to enable support for `<img src="url">` in the QtConsole.  I have no idea what that would require.

But I think you make a good point that a note should be added that the QtConsole _only_ supports embedded images.

Well, there is still the problem that having embeded=False For URL make the image disapearing if there is no internet connexion, if it's removed...etc

I would change the behavior to  `embed=True`  unless url **kwarg** is explicitely given or `embed=False` is explicitely given, so that notebook are **always** readable offline, and there is the least surprise when moving code from notebook to qtconsole.

In fine this is your call, but that how I feel for using `Image` for the first time. It feel to me that like `%loadpy`, using an url as first argument (by opsition as usin url kwarg) is fetching the data magically. 

If it's a question of size of the notebook, I don't think an image will make much difference in size with lot of graph embeded. 

> I would change the behavior to embed=True unless url kwarg is explicitly given

This seems pretty reasonable to me.  From the notebook's perspective, I still think when an Image is given by URL, it _rarely_ is actually desirable to embed the image, which has several disadvantages (in size, elegance, performance, etc.).  But if this has to be done with `Image(url='http...)`, and that makes default behavior less surprising, perhaps we should do it.

The costs of this change:
- increased notebook size
- increased unnecessary b64 data in notebook
- increased cost of displaying images (b64 encoding / decoding)
- increased network traffic when displaying images / loading notebook
  - kernel downloads image, never caching
  - kernel sends b64 image to Browser, which is significantly larger than the original
  - circumvents browser cache of images from urls

The benefits:
- consistency between QtConsole and Notebook
- Notebooks more likely to be complete in offline viewing

> Unless of course there is a good reason not to...

embed _should_ be False if a url is given, because that means the display data need only be `<img src="url"/>`, rather than including base64-encoded data.   This is a highly Notebook-centric behavior, as the QtConsole does not support non-embedded images at all, but it is _so much_ better in the notebook, that I think it's still the right choice.

Another solution would be to enable support for `<img src="url">` in the QtConsole.  I have no idea what that would require.

But I think you make a good point that a note should be added that the QtConsole _only_ supports embedded images.

Well, there is still the problem that having embeded=False For URL make the image disapearing if there is no internet connexion, if it's removed...etc

I would change the behavior to  `embed=True`  unless url **kwarg** is explicitely given or `embed=False` is explicitely given, so that notebook are **always** readable offline, and there is the least surprise when moving code from notebook to qtconsole.

In fine this is your call, but that how I feel for using `Image` for the first time. It feel to me that like `%loadpy`, using an url as first argument (by opsition as usin url kwarg) is fetching the data magically. 

If it's a question of size of the notebook, I don't think an image will make much difference in size with lot of graph embeded. 

> I would change the behavior to embed=True unless url kwarg is explicitly given

This seems pretty reasonable to me.  From the notebook's perspective, I still think when an Image is given by URL, it _rarely_ is actually desirable to embed the image, which has several disadvantages (in size, elegance, performance, etc.).  But if this has to be done with `Image(url='http...)`, and that makes default behavior less surprising, perhaps we should do it.

The costs of this change:
- increased notebook size
- increased unnecessary b64 data in notebook
- increased cost of displaying images (b64 encoding / decoding)
- increased network traffic when displaying images / loading notebook
  - kernel downloads image, never caching
  - kernel sends b64 image to Browser, which is significantly larger than the original
  - circumvents browser cache of images from urls

The benefits:
- consistency between QtConsole and Notebook
- Notebooks more likely to be complete in offline viewing


Resolving patch:
diff --git a/IPython/core/display.py b/IPython/core/display.py
--- a/IPython/core/display.py
+++ b/IPython/core/display.py
@@ -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
@@ -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)
@@ -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):


Test patch: