From 830bdac147815ac97d6f8c421d23cffebbd15b73 Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Thu, 22 May 2014 13:55:44 +0200 Subject: [PATCH] Fix PHRAS-122 Thumbnails are not centered properly --- lib/Alchemy/Phrasea/Twig/Fit.php | 27 +++++++++++++++++++++--- templates/web/common/thumbnail.html.twig | 2 ++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/Alchemy/Phrasea/Twig/Fit.php b/lib/Alchemy/Phrasea/Twig/Fit.php index b2ef2fe0dd..4a3b22f531 100644 --- a/lib/Alchemy/Phrasea/Twig/Fit.php +++ b/lib/Alchemy/Phrasea/Twig/Fit.php @@ -39,7 +39,17 @@ class Fit extends \Twig_Extension } $height = $width / $content['width'] * $content['height']; - $top = ($box['height'] - $height) / 2; + + $left = 0; + $top = 0; + + if ($contentRatio > 1) { + // mode landscape + $top = ($box['height'] - $height) / 2; + } elseif ($contentRatio < 1) { + // mode portrait + $left = ($box['width'] - $width) / 2; + } } else { if ($box['height'] > $content['height']) { $height = $content['height']; @@ -48,13 +58,24 @@ class Fit extends \Twig_Extension } $width = $height * $contentRatio; - $top = ($box['height'] - $content['height'] / 2); + + $left = 0; + $top = 0; + + if ($contentRatio > 1) { + // mode landscape + $top = ($box['height'] - $height) / 2; + } elseif ($contentRatio < 1) { + // mode portrait + $left = ($box['width'] - $width) / 2;; + } } return array( 'width' => round($width), 'height' => round($height), - 'top' => round($top) + 'top' => round($top), + 'left' => round($left) ); } } diff --git a/templates/web/common/thumbnail.html.twig b/templates/web/common/thumbnail.html.twig index 5200055e4c..a72c04a1fd 100644 --- a/templates/web/common/thumbnail.html.twig +++ b/templates/web/common/thumbnail.html.twig @@ -11,6 +11,7 @@ "width":original_w, "height":original_h, "top":0, + "left": 0 } %} {% elseif record_type == 'FLEXPAPER' %} {% set original_w = 800 %} @@ -20,6 +21,7 @@ "width":800, "height":600, "top":0, + "left": 0 } %} {% else %} {% set original_h = thumbnail.get_height() > 0 ? thumbnail.get_height() : 120 %}