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

Display Image in Qtconsole #1614

Closed
Carreau opened this issue Apr 16, 2012 · 5 comments · Fixed by #1616
Closed

Display Image in Qtconsole #1614

Carreau opened this issue Apr 16, 2012 · 5 comments · Fixed by #1616
Milestone

Comments

@Carreau
Copy link
Member

Carreau commented Apr 16, 2012

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

@minrk
Copy link
Member

minrk commented Apr 16, 2012

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.

@minrk
Copy link
Member

minrk commented Apr 16, 2012

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

@Carreau
Copy link
Member Author

Carreau commented Apr 16, 2012

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.

@minrk
Copy link
Member

minrk commented Apr 16, 2012

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

@Carreau
Copy link
Member Author

Carreau commented Apr 18, 2012

hum...
I'm totally unable to display jpeg in the qtconsole...

from IPython.core.display import *
Image('http://github.enthought.com/mayavi/mayavi/_images/example_potential_ipython.jpg', embed=True)

Out[3]: <IPython.core.display.Image at 0x10ebdde50>

Any idea why ? I tried specifying the format='jpg' without luck.

@Carreau Carreau closed this as completed in 19cfeef May 2, 2012
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014
Embed image as default to work in qtconsole unless url kwarg is set
explicitely

fixes ipython#1614
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants