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

Limit of setImageValue not working #1825

Open
Jenassa opened this issue Feb 17, 2020 · 1 comment · May be fixed by #1950
Open

Limit of setImageValue not working #1825

Jenassa opened this issue Feb 17, 2020 · 1 comment · May be fixed by #1950

Comments

@Jenassa
Copy link

Jenassa commented Feb 17, 2020

Describe the Bug

I use the template processor, to edit an existing Word file. When I want to set an image, the defined limit is not being considered. If the limit in setImageValue() is set to 1, all occurences are replaced and not only one. However, the limit when using setValue() works fine.

Steps to Reproduce

<?php
require __DIR__ . '/vendor/autoload.php';

$wordDoc = new TemplateProcessor($pathToDocument);
$wordDoc->cloneBlock($nameOfTheBlockToBeCloned, $numberOfElements);

foreach ($elements as $element) {
	$wordDoc->setValue('element_name', $element->getName), 1);
	$wordDoc->setImageValue('element_picture', $pathToPicture, 1);
}

Expected Behavior

The image of an element should be only set for one occurence of 'element_picture'.

Current Behavior

The image of the first element is set for all occurences of 'element_picture'.

Context

Please fill in your environment information:

  • PHP Version: 7.4
  • PHPWord Version: 0.17.0 via composer
@tuyouyu
Copy link

tuyouyu commented Feb 20, 2020

我认为自带的图片替换不好用,所以,我这几天也在折腾这个,后来发现,可以用模版图片来替换,我的替换数据源是编码了base64的字符串,所以,我直接,在模版里面,就用一个1像素的图片来填充,然后每次操作模版的时候把实际的base64替换掉/word/media里面的图片,通过xml,解析到目录里面的图片源,然后编码base64进行替换。实际上1像素的,base64只有很短的一行。。。这样做的好处,是,我可以不用关系图片的格式问题,例如:悬浮文字上方等。。。直接替换图片的数据,保留图片的模版格式。。。

ponsifiax added a commit to ponsifiax/PHPWord that referenced this issue Oct 21, 2020
@ponsifiax ponsifiax linked a pull request Oct 21, 2020 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants