Forum


Replies: 3   Views: 3035
How do i scale an image to a given height?
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 Vlad123  · 07-08-2017 - 15:04

Is there a way to scale images to a given height value without breaking the aspect ratio while adding them with addImage() or otherwise? Something like saying

$image->addImage([
    'src' => 'path/to/image.png',
    'height' => 500,
    'width' => 'auto'
]);

So that all the different images i'm adding would have same height and different width in correspondace with the aspect ratio.

Thank you in advance for your answer.

Posted by admin  · 07-08-2017 - 15:58

Hello,

If you set a height value but not a width value (or vice versa), phpdocx calculates the width from the aspect ratio using the PHP getimagesize function.

Regards.

Posted by Vlad123  · 08-08-2017 - 11:15

Hello,

thank you for your answer. Somehow it is not happening in my project, the images remain stretched or squeezed.

Posted by admin  · 08-08-2017 - 11:44

Hello,

Which license and version of phpdocx are using?

Regards.