From 96820c5d0fdf2cafd957ffb3184345e59c4d5b59 Mon Sep 17 00:00:00 2001 From: grosroro Date: Tue, 29 May 2012 10:32:37 +0200 Subject: [PATCH] Keep ratio --- src/FFMpeg/FFMpeg.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/FFMpeg/FFMpeg.php b/src/FFMpeg/FFMpeg.php index e6b78bf..8cbebc9 100644 --- a/src/FFMpeg/FFMpeg.php +++ b/src/FFMpeg/FFMpeg.php @@ -250,9 +250,21 @@ class FFMpeg extends Binary } } } + + $originalRatio = $originalWidth / $originalHeight; + + $targetRatio = $format->getWidth() / $format->getHeight(); + + if($targetRatio >= $originalRatio){ + $height = $format->getHeight(); + $width = $format->getHeight() * $originalRatio; + }else{ + $width = $format->getWidth(); + $height = $format->getWidth() / $originalRatio; + } - $width = $this->getMultiple($originalWidth, 16); - $height = $this->getMultiple($originalHeight, 16); + $width = $this->getMultiple($width, 16); + $height = $this->getMultiple($height, 16); break; }