Skip to content

Missing alt text for IPython.display.Image #13577

Description

@psychemedia

Image alt text when rendering IPython.display.Image is not displayed when Image() is created from filename or data elements. The test_image_alt_tag() only tests Image() objects created from url).

The following (included in tests) passes:

import nose.tools as nt

thisurl = "http://example.com/image.png"
img = Image(url=thisurl, alt="an image")
nt.assert_equal(u'<img src="%s" alt="an image"/>' % (thisurl), img._repr_html_())

The following two cases do render an image but fail to produce alt text (indeed, they don't seem to return __repr_html__()?

from numpy import random
import matplotlib.pyplot as plt

x = random.randint(10, size=(10))
y = random.randint(10, size=(10))

plt.scatter(x, y)
img_fn = 'example.png'
plt.savefig(img_fn)

img2 = Image(filename=img_fn, alt="another image")
# _repr_html_() returns None
assert img2._repr_html_() == None

nt.assert_equal(u'<img src="%s" alt="another image"/>' % (img_fn), img2._repr_html_())

"""
AssertionError: '<img src="example.png" alt="another image"/>' != None
"""

and:

with open(img_fn, "rb") as image:
    img_bytes = bytearray( image.read() )
    
    img3 = Image(filename=img_fn, alt="another image")
    repr_html = img3._repr_html_()
    
    # _repr_html_() returns None
    assert img3._repr_html_() == None

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions