For my web site builder SBWG I've looked into ways to store image descriptions as meta data in the image file itself so it can be used as an img tag's alt
attribute. The subject is a bit of a mess. So I decided to summarise the problems that I see and suggest a way of implementing automatic image descriptions from meta tags anyway.
Problems
First of all, there is the main issue that a good image description depends on the context in which the image is shown. For the same picture one might want to name the persons depicted, what they are
wearing or their facial expressions if that is relevant, or the colours and contrasts between background and clothes and visible compression artefacts. In some other context, only the types of glasses worn
or the hairstyles might be relevant. For the purpose of this post, in order to look beyond this problem, I have to ignore the possibility of wrong image descriptions because of re-used files or files used
in several contexts. The creator, editor or curator of a web page or blog post must be responsible to make sure no wrong image description is present or used for the alt attribute. The same
is true for mis-usage of meta tags, for example when some image editing software automatically uses a description field to store its copyright notice without the user's knowledge.
A script that automatically extracts the first string it find among a list of XMP fields could just as well find an unrelated string, the string 'none', a badly written alt text, one that was written for a different context or a string that was not meant to serve as the alt text to the image. Many of the fields that are listed above are meant to store something else than an alt text. Overall it is entirely expected that this method will not extract a useful alt text from the vast majority of images, simply because hardly anybody bothers to write them. I plan to use this method anyway, as a fallback, to cover for the cases where I myself couldn't be bothered. Writing a meaningfiul alt text for the context in which the image is used is still the only way to make sure that there is one.
So looking for a string in all of those fields and inserting it as the alt text in <img> is not correct unless you know that a good alt text has been stored there. Doing so anyway makes
this an experimentive feature. Using it with real image files from different sources will show if it is of much help or not even usable.
exiftool
The easiest free way of extracting meta data from image files is using exiftool. It supports more than just EXIF data and the list of supported file types is quite comprehensive in the image
department. Then the main question is which tags to use. There is no widely used standard for storing image descriptions for alt attributes.
IPTC defined the new tags
'Alt Text (Accessibility)' and
'Extended Description (Accessibility)' in 2024. But they seem that it is catching on
slowly. Before this tag was defined, many different tags were used by different projects, editing software and people. Additionally XMP tags aren't always implemented correctly; So the name of the tags can
differ between different tools and software versions. After my research into which tags are mentioned to be used for similar purposed, I've compiled the following ordered list of tags that should be checked
when generating HTML code with images.
Selection of Tags
- XMP-iptcCore:ExtDescrAccessibility
- Iptc4xmpCore:ExtDescrAccessibility
- ExtDescrAccessibility
- XMP-iptcCore:AltTextAccessibility
- Iptc4xmpCore:AltTextAccessibility
- AltTextAccessibility
- XMP:dc:description
- dc:description
- IPTC:Caption-Abstract
- XMP:ImageDescription
- XMP:Descrption
- ImageDescription
- Description
- XMP:Headline
- Headline
- IPTC:Headline
- XMP-photoshop:Headline
- XMP-dc:Title
- dc:title
- Title
- IPTC:ObjectName
- Iptc4xmpExt:AOTitle
- AOTitle
This list does not contain some tags for which I've found evidence that they are used for image descriptions, but not commonly enough (e.g. when only one not too widely used image editor writes it). It's hard to decide whto end the list. There will always be some weird tool, some conversion script or some old camera that uses yet another tag. But I think I've made a reasonable decision in the length of the list. Some of the above are not according to the respective standard or don't belong in most image file types. But I argue it's worth checking for them because there's not much cost to it and people don't always follow standards exactly, thus manually tagging images or creating software that tags images with fields in the wrong namespace or with the same fields across all image file types. Some of the tags listed (Title, Headline) aren't meant for image descriptions. But it has been suggested to use them for short descriptions in the past. Plus I argue if there is an image title, but no description or alt text whatsoever, it is still better to use the title than to not have an alt text at all. Other fields may be worthwhile to implement, too (Credit Line, Creator's Contact Info, Copyright Notice or others depending on the application). For a really extensive alt text the following format could be used, if those fields are filled: "[Image Title] by [Credit] ([Contact Email]): [ExtDescrAccessibility]"
Additionally to the tags mentioned, many XMP tags (e.g. Iptc4xmpCore:AltTextAccessibility, Iptc4xmpCore:ExtDescrAccessibility, dc:Description) can store values in different languages. Those could be respected as well if the language of the generated web page is known. Checking if any are set and use one if not empty should be simple. For those file formats that don't support XMP tags and those not supported by exiftool, I'm not aware of any meta data tags that do the job. The above list is for image files in general. Other file types may have other/additional tags that are useful for similar purposes to the img tags alt attribute. Video file formats definitely have several different additional description fields. Those would be interesting to extract and display, too.
For a clean implementation without so many different tags, only AltTextAccessibility and maybe ExtDescrAccessibility are necessary. Those are the most "official" ones and will
likely become the most widely used for image descriptions.