Merge pull request #1083 from nlegoff/fix-phras-122

[3.8] Fix PHRAS-122 Thumbnails are not centered
This commit is contained in:
Nicolas Le Goff
2014-05-22 19:04:10 +02:00
2 changed files with 26 additions and 3 deletions

View File

@@ -39,7 +39,17 @@ class Fit extends \Twig_Extension
} }
$height = $width / $content['width'] * $content['height']; $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 { } else {
if ($box['height'] > $content['height']) { if ($box['height'] > $content['height']) {
$height = $content['height']; $height = $content['height'];
@@ -48,13 +58,24 @@ class Fit extends \Twig_Extension
} }
$width = $height * $contentRatio; $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( return array(
'width' => round($width), 'width' => round($width),
'height' => round($height), 'height' => round($height),
'top' => round($top) 'top' => round($top),
'left' => round($left)
); );
} }
} }

View File

@@ -11,6 +11,7 @@
"width":original_w, "width":original_w,
"height":original_h, "height":original_h,
"top":0, "top":0,
"left": 0
} %} } %}
{% elseif record_type == 'FLEXPAPER' %} {% elseif record_type == 'FLEXPAPER' %}
{% set original_w = 800 %} {% set original_w = 800 %}
@@ -20,6 +21,7 @@
"width":800, "width":800,
"height":600, "height":600,
"top":0, "top":0,
"left": 0
} %} } %}
{% else %} {% else %}
{% set original_h = thumbnail.get_height() > 0 ? thumbnail.get_height() : 120 %} {% set original_h = thumbnail.get_height() > 0 ? thumbnail.get_height() : 120 %}