Skip to content

Conversation

@n3011
Copy link
Contributor

@n3011 n3011 commented May 4, 2023

Changes proposed in this pull request:

  • Add _repr_jpg_ and _repr_jpeg_ method for ipython display (similar to currently existing _repr_png_)

Signed-off-by: Ishant Mrinal Haloi <[email protected]>
@radarhere
Copy link
Member

If I understand correctly, this is not just for passing an image object directly to IPython, like in #1090 (comment)

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

and not just for IPython.display.display, but specifically for IPython.display.display_jpeg, yes?

@n3011
Copy link
Contributor Author

n3011 commented May 5, 2023

If I understand correctly, this is not just for passing an image object directly to IPython, like in #1090 (comment)

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

and not just for IPython.display.display, but specifically for IPython.display.display_jpeg, yes?

Yes this is display_jpeg.

@radarhere radarhere changed the title Add _repr_jpg_ for ipython display Added _repr_jpg_ for IPython display May 5, 2023
src/PIL/Image.py Outdated
)

def _repr_png_(self):
def _repr_image(self, format):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change format to something that doesn't shadow a builtin?

@n3011 n3011 changed the title Added _repr_jpg_ for IPython display Added _repr_jpeg_ for IPython display May 12, 2023
@radarhere radarhere added the JPEG label May 13, 2023
n3011 and others added 2 commits May 13, 2023 07:32
Co-authored-by: Ondrej Baranovič <[email protected]>
Co-authored-by: Andrew Murray <[email protected]>
Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@radarhere
Copy link
Member

Release notes have now been added - https://pillow--7135.org.readthedocs.build/en/7135/releasenotes/10.0.0.html#support-display-jpeg-in-ipython

@hugovk hugovk merged commit a58034b into python-pillow:main May 16, 2023
@n3011 n3011 deleted the jpg_repr branch May 16, 2023 09:20
@radarhere radarhere changed the title Added _repr_jpeg_ for IPython display Added _repr_jpeg_ for IPython display_jpeg May 16, 2023
@radarhere radarhere changed the title Added _repr_jpeg_ for IPython display_jpeg Added _repr_jpeg_() for IPython display_jpeg May 17, 2023
@smason
Copy link
Contributor

smason commented Jul 4, 2023

I'm wondering what the purpose of this change is. I'm interested to know if it's mainly to support calling display_jpeg on an image?

If so, this seems to be having unintended consequences as I'm now getting both a PNG and JPEG encoded image saved in each cell. For example, a cell I just created includes:

     "data": {
      "image/jpeg": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsI>
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAC7kAAAu5CAAAAABw4BI+AAEAAElEQVR4AQBSgK1/AdfANnmuHKdSoc6W0wL98OSB+b>
      "text/plain": [
       "<PIL.Image.Image image mode=L size=3001x3001>"
      ]
     },

which might well double resulting .ipynb file sizes, depending on how either encoder deals with the image.

@radarhere
Copy link
Member

I'm interested to know if it's mainly to support calling display_jpeg on an image?

Yes. That is what the original poster was after, and that is what we have announced.

Discussion of double images can continue in #7259

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants