Via jupyter/enhancement-proposals#120 which mentions previously added support to IPython's rendering of image alt text (#12864), albeit apparently limited to images pulled from URLs (#13577), I was wondering whether it might be useful to optionally seed the alt tag from description text embedded within an image?
For example, description data could be accessed as description data from a PNG file as:
from PIL import Image
import PIL.PngImagePlugin
def read_png_metadata(filename):
with Image.open(filename) as img:
metadata = {
"text": img.text,
"info": img.info
}
return metadata
# Assuming you've saved your image as 'tips_scatter.png'
filename = 'tips_scatter.png'
metadata = read_png_metadata(filename)
print("Image Metadata:")
for key, value in metadata.items():
print(f"{key}:")
if isinstance(value, dict):
for k, v in value.items():
print(f" {k}: {v}")
else:
print(f" {value}")
alt_text = metadata['info'].get('Description', '')
So it might be useful to be able to render something like Image(..., extract_alt="Description').
The JEP issue also points to matplotalt, a simple project that mooted seeding matplotlib alt text from image object properties and then embedding that text inside the generated images. It is easy enough to imagine extending that sort of approach to other charting packages, such as seaborn. There would be even more of drive for this if IPython handled this natively, rather than eg a requirement to build custom mimetype handlers in JupyterLab that can extract text from images and then render it as alt text.
Via jupyter/enhancement-proposals#120 which mentions previously added support to IPython's rendering of image alt text (#12864), albeit apparently limited to images pulled from URLs (#13577), I was wondering whether it might be useful to optionally seed the alt tag from description text embedded within an image?
For example, description data could be accessed as description data from a PNG file as:
So it might be useful to be able to render something like
Image(..., extract_alt="Description').The JEP issue also points to
matplotalt, a simple project that mooted seeding matplotlib alt text from image object properties and then embedding that text inside the generated images. It is easy enough to imagine extending that sort of approach to other charting packages, such asseaborn. There would be even more of drive for this if IPython handled this natively, rather than eg a requirement to build custom mimetype handlers in JupyterLab that can extract text from images and then render it as alt text.