From 4f67937f55e08c88e060102a34973fb9ec1ac967 Mon Sep 17 00:00:00 2001 From: nico Date: Wed, 4 Mar 2015 23:17:12 +0100 Subject: [PATCH] Maintain given width or height from settings if one of those is provided --- app/Controller/Component/QimageComponent.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/Controller/Component/QimageComponent.php b/app/Controller/Component/QimageComponent.php index 3578f0c..612aab1 100644 --- a/app/Controller/Component/QimageComponent.php +++ b/app/Controller/Component/QimageComponent.php @@ -242,15 +242,21 @@ public function resize($data){ // If width or height not defined, it's necessary calculate proportional size if (!($width > 0 && $height > 0)){ - + $source_side; + $source_origin; + // Verify if image is horizontal or vertical if ($original_height > $original_width){ - $height = ($data['width'] > 0) ? $data['width'] : $data['height']; - $width = ($height / $original_height) * $original_width; + $source_side = ($data['width'] > 0) ? $data['width'] : $data['height']; + $source_origin = ($data['width'] > 0) ? $original_width : $original_height; } else { - $width = ($data['height'] > 0) ? $data['height'] : $data['width']; - $height = ($width / $original_width) * $original_height; + $source_side = ($data['height'] > 0) ? $data['height'] : $data['width']; + $source_origin = ($data['height'] > 0) ? $original_height : $original_width; } + + $factor = ($source_side / $source_origin); + $height = $factor * $original_height; + $width = $factor * $original_width; }