Improve Alt Text generation when the Image is used in content

Created on 1 July 2025, 4 days ago

Problem/Motivation

Current alt text generation lacks context; the same image may require different descriptions depending on its use. For example, a photo of people around a laptop should focus on the people if it's in an article about diversity, but on the laptop if it's about technology.

When an image is uploaded to the Media library, the ai_image_alt_text module provides an image description. This literal description can be useful for editors to locate an appropriate image for use with their content, but once used with content the alt text should be altered to be appropriate for the content it is now associated with.

Given that a single image can be used in multiple places, the original alt text should remain in place and the image when it is referenced, should get some new alt text.

There are articles which explain the issue, such as:
https://accessibility.huit.harvard.edu/describe-content-images

AI Image Alt text should assist in generating the new alt text, which means it needs to also consider the article in which the image has been placed.

Steps to produce

Install Drupal CMS
Upload an image such as the image in the article above under the heading "Consider the Context"
Write 2 articles:

  1. one about students enjoying the nice weather on the lawn
  2. the other about the building "Hollis Hall" and its surrounding common spaces

Note that the same alt text is now used in both cases.

The alt text for the image in each of these articles should be different to represent the images in a different context.

Proposed resolution

I have created a recipe that can be applied to Drupal CMS
https://github.com/thegbomb/article_contextual_images
This creates a new content type with a contextual image field.
This field utilises the media_library_media_modify to provide a way to have alt text saved on the referenced field, but it leaves the original alt text as is.

The module is a workaround created to solve a problem outline in this core issue: [META] Improve workflows for image alternative text Active

Remaining tasks

Utilising this solution, the AI Image Alt text module should be able to ascertain if the media item is being referenced in a node and then extract content from that node to offer more context-aware alt text.

Drupal CMS has already used a focus field for SEO tools, perhaps that can be used again here. The Title certainly should be considered, along with perhaps the Summary or Content fields.

It may be best if 2 or 3 options could be offered, so that the editor can use their intention awareness and choose the most appropriate alt text.

More information regarding why accurately described alt text is not suitable can be read at:

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom the_g_bomb

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024