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

Replace all image by their alttext attribute #2587

Open
l4nos opened this issue Mar 19, 2024 · 0 comments
Open

Replace all image by their alttext attribute #2587

l4nos opened this issue Mar 19, 2024 · 0 comments

Comments

@l4nos
Copy link

l4nos commented Mar 19, 2024

Essentially the idea is to loop over every image in every document part, if it has an "alt text" attribute set, look in the merge data for either image data or an image url, store it in a temp file, then load that into the relations using the existing functions and update the rid.

I've actually written the code in my own fork of this and tested it and it works brilliantly.

A feature like this i've seen a lot of people on stackoverflow asking for, and I couldn't find a decent solution, one that honoured and reused the original functions of TemplateProcessor as much as possible, therefore I took a stab at it myself.

https://github.com/Lane-Ventures/PHPWord

The developer consuming this package would simply feed in their flattened data array in the same way they do for setValues, and it would work just for images.

        $templateProcessor->setImagesByAltText($flattenedData);

If you aren't willing to add this into the main package, im happy to just keep using this in my own package, I just posted the solution here as I've seen a lot of people hutning for this.

I'm also working on a function to handle images inside repetable table rows which should sit nicely with cloneRowAndSetValues. I'm also looking to incorporate in how to handle preserving the aspect ratio of the source image or the placeholder.

Any questions, queries or crticisms are welcomed.

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

No branches or pull requests

1 participant