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

Autogenerate alt text for images #2910

Closed
KyleAMathews opened this issue Nov 13, 2017 · 14 comments · May be fixed by tejzpr/gatsby#61
Closed

Autogenerate alt text for images #2910

KyleAMathews opened this issue Nov 13, 2017 · 14 comments · May be fixed by tejzpr/gatsby#61

Comments

@KyleAMathews
Copy link
Contributor

KyleAMathews commented Nov 13, 2017

https://twitter.com/sarah_edo/status/930083568411217920

We could add support for this to gatsby-transformer-sharp so every image includes an alt text.

@KyleAMathews KyleAMathews changed the title Autogenerate alt tags for images Autogenerate alt text for images Nov 13, 2017
@vivek12345
Copy link

@KyleAMathews Would this be a difficult task for a newbie to take up?

@KyleAMathews
Copy link
Contributor Author

Nope!

A PR adding this would need

Do you want to take this on?

@vivek12345
Copy link

Yes I would want to take this up, but I will keep it open for other's as well if I take too much time to get this done.

@KyleAMathews
Copy link
Contributor Author

Awesome! Let us know your progress! Also don't feel bad about throwing up a partially finished PR.

@fk
Copy link
Contributor

fk commented Nov 13, 2017

Go @vivek12345! 👍

@vivek12345
Copy link

Thank you :)

@fk
Copy link
Contributor

fk commented Nov 13, 2017

🙌

Btw. gatsby-remark-copy-linked-files also generates a default alt text for HTML images in Markdown (<img src=…>) via the image filename here:

// Generate default alt tag
const srcSplit = initialImageSrc.split(`/`)
const fileName = srcSplit[srcSplit.length - 1]
const fileNameNoExt = fileName.replace(/\.[^/.]+$/, ``)
const defaultAlt = fileNameNoExt.replace(/[^A-Z0-9]/gi, ` `)
image.attr(`alt`, image.attr(`alt`) ? image.attr(`alt`) : defaultAlt)

AFAIU this mimics what happens to regular Markdown images that do not have an user-defined alt text (![](../../image.jpg)). Would be nice to somehow generalize this, too (not necessarily in one go)!

@KyleAMathews
Copy link
Contributor Author

Yeah! Let's get this in gatsby-plugin-sharp and then add it like normal to all the usual places.

@benjaminhoffman
Copy link
Contributor

When we think about the point of alt text, it's for a11y (screen readers) and SEO (tells googlebot what this is an image of). In order of preference, it's better to have: 1) accurate, hand-typed alt text, then 2) empty string alt "", then 3) no alt text, and finally 4) incorrect alt text.

Assuming the above is true, a feature like this could cause issues b/c auto generating alt text from horribly-named images will jump to the fourth option. If this feature gets included then maybe a warning or strong notice to the user that their images should be descriptive would be helpful.

Or instead, would it be better to check if an alt text is included and if not, add a warning informing the user that they should include an alt text in their image?

@Undistraction
Copy link
Contributor

Undistraction commented May 23, 2018

There is also the SEO factor to consider. The way you would name an image for Google is not (necessarily) the way you would describe an image with alt text.

Given that we are only talking about images defined in frontmatter (because it's easy to add alt text to a markdown image), could the alt text be added in the frontmatter where the link to the image is defined and added to the ImageSharp by gatsby-transformer-sharp? There would need to be a simple convention to link an alt tag to an image, for example appending _alt to the image key:

title: Example
slug: example
primaryImage: ./images/example.jpg
primaryImage_alt: Picture of an example
secondaryImage: ./images/secondary.jpg
secondaryImage_alt: Picture of an example

@KyleAMathews
Copy link
Contributor Author

Cool idea but it'd be in a plugin so closing

@Undistraction
Copy link
Contributor

Undistraction commented Sep 8, 2018

@KyleAMathews I'd definitely argue this should be built and easy to use in for the simple reason that making it easy to use will mean more people will use it, which is better for accessibility. Alt tags play a very important role and should be supported out of the box imho.

@KyleAMathews
Copy link
Contributor Author

It'd be great for a community member to build. We use issues to track ongoing core work and as this isn't ongoing, I needed to close it. It is a great idea and if it ever becomes something we in core do, then we'll reopen in. Feel free to start a project around it now in your own repo!

@TylerBarnes
Copy link
Contributor

Using an image recognition api for this in a plugin would be killer.
https://twitter.com/sarah_edo/status/930083568411217920

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants