Forum


Replies: 2   Views: 252
Dynamic variable while using replaceplaceholderimage
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 admin  · 29-04-2024 - 09:57

Hello,

Sorry, but we are not sure if we understand your issue correctly.

Do you mean if you use the following code it runs correctly?:

$image_options = array(
    'height' => 2,
    'width' => 2,
    'target' => 'header',
);

$docx->replacePlaceholderImage('QRCODE', 'docs/image1.png' , $image_options);
$docx->createDocx('docs/'.$filename);

But if you use the following code it doesn't work?:

$qrcode_id = 'image1';

$image_options = array(
    'height' => 2,
    'width' => 2,
    'target' => 'header',
);

$docx->replacePlaceholderImage('QRCODE', 'docs/'.$qrcode_id.'.png' , $image_options);
$docx->createDocx('docs/'.$filename);

The only difference is that a variable is used to set the image path.

What is the value of $qrcode_id in your code?:

$qrcode_id = $_POST['qrcode_id'];

a string with the file path? an URL? a stream?

We have done some tests and everything is working correctly. For example, if we change the examples/Templates/replacePlaceholderImage/sample_1.php script included in the package to use a variable to set the image path and we run the following code:

$docx = new CreateDocxFromTemplate('../../files/placeholderImage.docx');

$imagePath = '../../img/';
$image_1 = array(
        'height' => 3,
        'width' => 3,
        'target' => 'header',
);

$docx->replacePlaceholderImage('HEADERIMG', $imagePath . 'logo_header.jpg', $image_1);
$docx->replacePlaceholderImage('LOGO', $imagePath . 'imageP3.png');

$docx->createDocx('example_replacePlaceholderImage_1');

the DOCX is generated correctly.

For further support please send to contact[at]phpdocx.com the most simple script that illustrates your code using phpdocx standalone (without external resources such as frameworks, databases...), the image you are adding (you can also send the DOCX template you are using) and the DOCX output you get. We'll check them.

Regards.