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

Silence exceptions in _repr_jpeg_ and _repr_png_ #7266

Merged
merged 5 commits into from
Jul 31, 2023

Commits on Jul 6, 2023

  1. Handle exceptions in _repr_jpeg_ and _repr_png_

    In 10.0.0 a _repr_jpeg_ implementation was added to the Image object to
    enable the use of display_jpeg() in IPython environments. However, in
    some cases the implementation of this method could result in an
    exception being raised while trying to generate the jpeg data. The best
    example is if the image data is in an RGBA format as a result of the
    object being created by opening a PNG file. In this case trying to save
    the Image object as a jpeg will error because the jpeg format can't
    represent the transparency in the alpha channel. This results in an
    exception being raised in the IPython/Jupyter context when outputing the
    image object. However, in cases like this IPython allows the repr
    methods to return None to indicate there is no representation in that
    format available. [1] This commit updates the _repr_png_ and _repr_jpeg_
    methods to catch any exception that might be raised while trying to
    generate the image data. If an exception is raised we treat that as not
    being able to generate image data in that format and return None
    instead.
    
    Related to python-pillow#7259
    
    [1] https://ipython.readthedocs.io/en/stable/config/integrating.html#custom-methods
    mtreinish committed Jul 6, 2023
    Configuration menu
    Copy the full SHA
    6d440ac View commit details
    Browse the repository at this point in the history
  2. Update src/PIL/Image.py

    Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
    mtreinish and radarhere authored Jul 6, 2023
    Configuration menu
    Copy the full SHA
    9517fec View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    6215cd3 View commit details
    Browse the repository at this point in the history

Commits on Jul 23, 2023

  1. Simplified code

    radarhere committed Jul 23, 2023
    Configuration menu
    Copy the full SHA
    e5c94ec View commit details
    Browse the repository at this point in the history

Commits on Jul 24, 2023

  1. Merge pull request #1 from radarhere/handle-repr-exceptions

    Simplified code
    mtreinish authored Jul 24, 2023
    Configuration menu
    Copy the full SHA
    2a55b14 View commit details
    Browse the repository at this point in the history