I have a pdf that is created using an image (so it has image's original dimensions)
Now, I am trying to scale it in its ratio to fit A4 pdf (width touching to sides and centering vertically).
This is the code I tried:
$imagick = new \Imagick();
$imagick->setResolution(576,576);
$imagick->readImage($path);
$imagick->resizeImage(2480,3508,\Imagick::FILTER_CUBIC,1);
$imagick->setCompressionQuality(80);
$imagick->setImageFormat('pdf');
$imagick->writeImage($path);
But it's disturbing the image ratio to fit full page (100% width & 100% height).
For example, original image 717x558:
Exported image,
However, what I am trying to achieve is this:
** Update **
$imagick = new \Imagick();
$imagick->readImage($path);
$imagick->resizeImage(595,842,\Imagick::FILTER_CUBIC,1);
$imagick->setBackgroundColor(new ImagickPixel('white'));
$imagick->setGravity ( Imagick::GRAVITY_CENTER );
$imagick->extentImage ( 595 , 843 , 0 , 0 );
$imagick->setImageFormat('pdf');
$imagick->writeImage($path);
Using this, this is the output (it's full page but lost the ratio):