Forum


Replies: 4   Views: 297
How to modify image's alt text
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by Bouillou  · 22-12-2021 - 11:16

Dear support,

I am using addImage  to insert a images in a document. My problem is that all images have automatically an alt text set with the absolute image path. I really need to remove the alt text but I don't find how in your documentation.

Here is the code I am using to add the image.

I have an advanced licence v10.0.

$options = array(
    'src' => $path,
    'imageAlign' => $align,
    'height' => $dimension['height'],
    'width' => $dimension['width'],
    'textWrap' => 0,
    'spacingTop' => 10,
    'spacingBottom' => 10,
    'spacingLeft' => 10,
    'spacingRight' => 10,
    'caption' => array('show_label' => false, 'text' => ''),
    'descr' => '',
    'description' => '',
    'title' => ''
);
$this->docx->addImage($options);

Thank you for your support and best regards,

S├ębastien Despont

Posted by admin  · 22-12-2021 - 11:52

Hello,

phpdocx 12 (https://www.phpdocx.com/news/post/phpdocx-v12-release-notes/223) added the following new option:

- New descr option in addImage to set a custom descr value instead of the image path.

to set a custom value to the descr option. As this option is available in phpdocx 12 but not in previous versions, you can test it using the trial package.

If this option is not set, the path is added. Previous versions of phpdocx add always the path to this attribute.

Regards.

Posted by Bouillou  · 22-12-2021 - 13:09

Please, can you tell where the source code can be modified to remove the current alt text set with the file path?

Best regards

Posted by admin  · 22-12-2021 - 15:04

Hello,

Although we recommend you upgrade to phpdocx 12 to be able to use the descr option and all other new features, if you want to change the source code manually, you need to update the following line in CreateImage.php:

$this->setName($args[0]['src']);

you can set any other value instead of the file path ( $args[0]['src'] ).

Regards.

Posted by Bouillou  · 24-12-2021 - 10:58

Customer since the version 5.5, I will ugrade next year to your current version. It is not the good time for me to do this at the end of the year.

Thank you for your support.