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

TemplateProcessor->setImageValue() #1170

Merged

Conversation

SailorMax
Copy link
Contributor

@SailorMax SailorMax commented Oct 25, 2017

Allow to put images in templates.

Fixes #1079
Fixes #939
Fixes #708

@SailorMax
Copy link
Contributor Author

This PR can solve next issues: #1079, #939 and #708

@FBnil
Copy link

FBnil commented Oct 25, 2017

But what about #1084 ? That one has more functionality.

However, both suffer from: Not using the PHPWord()->addImage() to make an image and let that part handle all the parameters you can give it.

I appreciate your time and you sharing your good code, though.

@SailorMax
Copy link
Contributor Author

@FBnil
Didn't saw it. Thanks.
My solution simpler -- without dimension convertings and without in template static image size per place. Second part is interesting!

You can choose the best for your self :)

@kaioken
Copy link

kaioken commented Nov 29, 2017

dude @SailorMax just wanted to say thank you for this ;) really help me out with your branch

@SailorMax
Copy link
Contributor Author

@kaioken
you are welcome :)

@phuongnguyenle
Copy link

I need to approval this request to resolve the same issue. Could you please help us?

@grayback6192
Copy link

@SailorMax There's a problem with the variables thats being written from the PHPWord here's a snippet.

//Creates Word File
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->addText('${Test}');
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('helloWorld.docx');
//Opens Word file
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('helloWorld.docx');
$templateProcessor->setImageValue("Test","test.png");
$templateProcessor->saveAs("Test.docx");

Here's the output
image

Whenever it is written with phpWord, it won't change the variable with image. Works fine on setValue()

@olegmifle
Copy link

Hi all!
Can anybody help me to install this fork via composer.json?

@bigpws
Copy link

bigpws commented Jan 31, 2018 via email

@SailorMax
Copy link
Contributor Author

@Skeptron
On template side:

  • ${search-image-pattern:[width]x[height]}
  • ${search-image-pattern:size=[width]x[height]}
  • ${search-image-pattern:width=[width]:height=[height]}

On php side:

  • $templateProcessor->setImageValue('search-image-pattern', array('path' => 'path/to/logo.png', 'width' => 100, 'height' => 100));

Brief documentation:
7959651

@Skeptron
Copy link

@SailorMax Thanks a lot, you rock!

@Skeptron
Copy link

Sorry to ask one more thing, but is there a way to keep original image size without having to code it? For some reason imported images are always very small. I can fix this by manually setting their size, but it's quite a hasstle considering I have 160+ images to import. Is there any way to say "keep the orginal size when importing"?

Thanks a lot

@SailorMax
Copy link
Contributor Author

SailorMax commented Jun 22, 2018

@Skeptron Currently you can get size by getimagesize() and setup it on php side. For better solution I need time to think :)

@ekohere
Copy link

ekohere commented Aug 17, 2018

why in mw project
Call to undefined method PhpOffice\PhpWord\TemplateProcessor::setImageValue()
setImageValue not found in php version 0.15.0 .

@SailorMax
Copy link
Contributor Author

SailorMax commented Aug 17, 2018

@ekohere Possible because this pull request is still unmerged with your 0.15

@ekohere
Copy link

ekohere commented Aug 17, 2018

what last version has support setImageValue?

@ekohere
Copy link

ekohere commented Aug 17, 2018

is there another way to insert images through the TemplateProcessor?

@SailorMax
Copy link
Contributor Author

@ekohere While this pull request not merged, no one version contain it.
In theory you can merge it into your local repository, but I don't know how.

@scuben
Copy link

scuben commented Oct 16, 2018

Would be great if that could be merged.

@troosan troosan added this to the v0.16.0 milestone Dec 3, 2018
@coveralls
Copy link

coveralls commented Dec 23, 2018

Coverage Status

Coverage decreased (-0.1%) to 94.538% when pulling d771461 on SailorMax:template_processor__set_image_value into e6496bf on PHPOffice:develop.

@troosan troosan merged commit d5da80b into PHPOffice:develop Dec 26, 2018
@SailorMax SailorMax deleted the template_processor__set_image_value branch March 1, 2019 13:30
@ranolrandria
Copy link

hi, I'm using phpword to insert image with setImageValue, I don't know but the first image don't show and the file word is corrupt

@SailorMax
Copy link
Contributor Author

hi, I'm using phpword to insert image with setImageValue, I don't know but the first image don't show and the file word is corrupt

Can you share the sample of source document?

@Ifriqiya
Copy link

Hi, I have this code to add an image to a document, $phpword->setImageValue('signature', $user->profile_photo_path); but I get the error: 'Invalid image: profile-photos/RajPxHv0I6PgE3CtLas2oKXZhZFXSOGUjegbUURe.jpg'. What can I do to resolve this?

@Ifriqiya
Copy link

The issue was with the image path, it appears it has to be a relative not absolute path. Correctly setting this path resolved the issue I faced and the image was set. Nothing invalid about it.

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