This is:
I asked that question on stackoverflow, but I'm sure that's no possible atm.
It should be possible to set an (external, internal) link on an image. At the moment (PHPWord version 0.16.0), it's only allowed to set text to a link (see "src/PhpWord/Element/Link.php"). And on an image element, I can't set a link.
What is you output format? docx or odt?
ODT has a special anchor named draw:a, so it should a special method. eg:
$section->addImage('img/img1.jpg',
[
'width' => 200,
'height' => 200,
'link' => '....'
]
);
When you set a link on an image the libreoffice writes this three node:
<draw:a>
<draw:frame>
<draw:image />
</draw:frame>
</draw:a>
unfortunately docx
I'm afraid this is currently not possible. The way word does this is
<w:drawing>
<wp:inline>
<wp:docPr id="1" name="Picture 1">
<a:hlinkClick xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" r:id="rId4"/>
</wp:docPr>
</wp:inline>
</w:drawing>
rId4 being defined as a relation.
Do you plan to add this feature in a future release? This is a highly needed feature!
I tested saving a file in odf format using the 'link' property on an image, and the link is not showing up in the odf file. When I right-click on the image and select "hyperlink", no link is defined.
We made this issue working in our environment. I don't know "how nice" we solved it. If it's more or less bulletproof, we can do a PR if you want. Let me check that...
We made this issue working in our environment. I don't know "how nice" we solved it. If it's more or less bulletproof, we can do a PR if you want. Let me check that...
Please post it if you can!
I was able to create a workaround by creating a Word VBA macro to loop through the images and add the links after PHPWord created the files. This worked, but it would be much easier if PHPWord could support this directly.
bountysource? Yeah, I want that baked. Small incentive deposited: https://www.bountysource.com/issues/74132279-set-a-hyperlink-on-a-image
Most helpful comment
We made this issue working in our environment. I don't know "how nice" we solved it. If it's more or less bulletproof, we can do a PR if you want. Let me check that...