Forum


Replies: 4   Views: 2640
How to replace a placeholder image by another image and keep second image proportions
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 Desoutter  · 30-10-2017 - 09:37

Hi,

Is it possible to replace an placeholder image with a new image with this constraints :

- The placeholder image fix the max with and the max height

- The new image keep proportions and fit to max width (or max height or both if they both have the same proportions)

PS : The placeholder image can be a word box or whatelse who can constraint the new image.

Thank you.

 

Posted by admin  · 30-10-2017 - 10:39

Hello,

Yes, you can use the sizes from the existing image or use the size from the new image.

This is the phpdoc of the size options of the method:

* 'width' (mixed): the value in cm (float) or 'auto' (use image size), 0 to not change the previous size
* 'height' (mixed): the value in cm (float) or 'auto' (use image size), 0 to not change the previous size
* 'dpi' (int): dots per inch. This parameter is only taken into account if width or height are set to auto.

You can set width and height values as 0 to keep the previous sizes or set new values (fixed or auto). Please note that if the images doesn't have the same dpi you may need to set a dpi.

Regards.

Posted by Desoutter  · 30-10-2017 - 12:26

Thank you,

But,  I would like the new image (I don't know the width and the height) keep this width/height ratio and fit in the placeholderbox.

Example :

- The placeholder box size is 200x200px.

- The new image  original size is 400x200px

In the final document, the image size must be 200x100px.

You known where I want to go?

Thank you :-)

 

 

 

Posted by admin  · 30-10-2017 - 12:41

Hello,

OK, we see. There's no option to get the size of a content that wraps other content. Using DOCXPath you could get some data, for example if you use a textbox, but it doesn't return other sizes such as table cells or paragraphs.

Regards.

Posted by Desoutter  · 30-10-2017 - 12:50

Ok, that's what I thought

Thank you :-)