php-image-resize
php-image-resize copied to clipboard
How can I get Resized Image With
trafficstars
I use php-image-resize via composer.
I have a crop action wich a bit special for my script.
At some point, I need to know the result of resizeToHeight action as image sizes. But the method does not keep the width result on properties or return as a result.
Here is my example.
<?php
//load composer
require_once './vendor/autoload.php';
use \Gumlet\ImageResize;
$sourceFilename = 'test.jpg';
$destFilename = 'result.jpg';
$imageCropWidth = 202;
$imageCropHeight = 267;
$image = new ImageResize($sourceFilename);
$image->resizeToHeight($imageCropHeight);
if ( $image->getSourceWidth() >= $image->getSourceHeight() )
{
$image->crop($imageCropWidth, $imageCropHeight);
}
else
{
//ALERT
//in this part, I need to know resized image Width
//$resizedWith = $image->getResizedImageWidth();
if( $resizedWith > $imageCropWidth )
{
$image->crop($imageCropWidth, $imageCropHeight);
}
}
$image->save($destFilename, IMAGETYPE_JPEG);
I tested again and I found a way wich my help others.
I used ratio calculation as you do.
$resizedWith = (int) ( $imageCropWidth * ( $imageCropHeight / $image->getSourceHeight() ) );
As a suggestion, you may implement this calculation as a method.
If you can create a PR, I am happy to merge it.