Forum


Replies: 2   Views: 1166
Add images next to each other
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 Knutsford  · 17-01-2020 - 14:57

How do I add three images next to each other? Thanks

Posted by admin  · 17-01-2020 - 15:45

Hello,

You need to use WordFragments and an array. For example:

<?php

require_once 'classes/CreateDocx.php';

$docx = new CreateDocx();

$imageA = new WordFragment($docx);
$options = array(
    'src' => 'image1.png',
    'scaling' => 40,
);
$imageA->addImage($options);

$imageB = new WordFragment($docx);
$options = array(
    'src' => 'image2.png',
    'scaling' => 40,
);
$imageB->addImage($options);

$imageC = new WordFragment($docx);
$options = array(
    'src' => 'image3.png',
    'scaling' => 40,
);
$imageC->addImage($options);

$runs = array();
$runs[] = $imageA;
$runs[] = $imageB;
$runs[] = $imageC;
$docx->addText($runs);

$docx->createDocx('output');

You can find similar samples that explains how to add inline contents in the same paragraph in all packages (examples/Core/addImage/sample_2.php, examples/Core/addText/sample_3.php) and on the API documentation page (https://www.phpdocx.com/api-documentation/word-content/add-paragraph-text-Word-document-with-PHP).

For further information about WordFragments, please check https://www.phpdocx.com/documentation/practical/wordfragments-and-wordml

Regards.

Posted by Knutsford  · 17-01-2020 - 16:58

Brillant thanks