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

Consider implementing _repr_png_ for the Image object #1090

Closed
payne92 opened this issue Jan 28, 2015 · 6 comments
Closed

Consider implementing _repr_png_ for the Image object #1090

payne92 opened this issue Jan 28, 2015 · 6 comments

Comments

@payne92
Copy link

payne92 commented Jan 28, 2015

Given the popularity of IPython, consider implementing a _repr_png_() method for the Image object, which just returns the object in PNG form. If this method exists on an object, the IPython notebook will display the rich image representation in-line.

See: http://nbviewer.ipython.org/github/adrn/ipython/blob/1.x/examples/notebooks/Part%205%20-%20Rich%20Display%20System.ipynb

This can be done without dependency on or reference to IPython.

@wiredfool
Copy link
Member

I've got a branch with that method in it now, (https://github.com/wiredfool/Pillow/tree/repr_png) but it does not seem to trigger iPython's display hooks. Can you give a step by step to test it, or determine what else needs to be added to make it work?

@payne92
Copy link
Author

payne92 commented Jan 28, 2015

The method is _repr_png_() -- your implementation is missing the trailing underscore in the name.

To test in an IPython web notebook:

from PIL import Image
im = Image.new("RGB", (512, 512), "blue")
im

IPython will attempt to render the last value. When it finds _repr_png_(), it will render it.

@hugovk
Copy link
Member

hugovk commented Jan 28, 2015

The problem was GitHub interpreted the underscores as italic markup. I've edited to wrap backticks ` around the function to make sure it's in code markup!

@payne92
Copy link
Author

payne92 commented Jan 28, 2015

Ah, my bad -- sorry about that. I should have checked the preview more carefully.

@wiredfool
Copy link
Member

Ah, much better. Works now.

@hugovk
Copy link
Member

hugovk commented Jan 30, 2015

Implemented via #1091, thanks.

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

No branches or pull requests

3 participants