PHPOffice / PHPWord

A pure PHP library for reading and writing word processing documents
https://phpoffice.github.io/PHPWord/
Other
7.27k stars 2.7k forks source link

Add the ability to add alt text to images #2630

Open doom-cat opened 4 months ago

doom-cat commented 4 months ago

Describe the problem

Currently, there appears to be no means to add alt text to images in Word2007 Writer. Alt text is important because it is displayed in lieu of the image if the image fails to load for some reason. It is also an important accessibility feature, since it allows screen readers to describe the content of an image if the image is not visible to a user.

Describe the expected behavior

The addImage usage should change from: $section->addImage($src, [$style]); to: $section->addImage($src, [$style], [string $altText]);

I have code that adds this capability, but it would help to know if the $name variable is used with images, so that I can avoid conflicts in the order of Image properties. In file src/PhpWord/Element/Image.php, line 149 shows the following: public function __construct($source, $style = null, $watermark = false, $name = null)

The $name variable is not addressed in any documentation that I found, but it does appear on line 73 of tests/PhpWordTests/Element/ImageTest.php. If it is not used, then I would like to change the above constructor as follows, since it will provide a simpler call to add an image that is not a watermark: public function __construct($source, $style = null, $altText = null, $watermark = false, $name = null)

If $name is used, then I will put the new $altText property at the end: public function __construct($source, $style = null, $watermark = false, $name = null, $altText = null)

Priority

Progi1984 commented 2 months ago

@doom-cat Have you got a sample docx file with image with an alt text ?

If yes, Could you give me for analysis, please ?