diff --git a/lib/Alchemy/Phrasea/Application.php b/lib/Alchemy/Phrasea/Application.php
index 33e0e610e2..2634a5dfa9 100644
--- a/lib/Alchemy/Phrasea/Application.php
+++ b/lib/Alchemy/Phrasea/Application.php
@@ -103,6 +103,7 @@ use Alchemy\Phrasea\Core\Provider\UnicodeServiceProvider;
use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Exception\LogicException;
use Alchemy\Phrasea\Twig\JSUniqueID;
+use Alchemy\Phrasea\Twig\Fit;
use Alchemy\Phrasea\Twig\Camelize;
use Alchemy\Phrasea\Twig\BytesConverter;
use FFMpeg\FFMpegServiceProvider;
@@ -589,6 +590,7 @@ class Application extends SilexApplication
// add filters truncate, wordwrap, nl2br
$twig->addExtension(new \Twig_Extensions_Extension_Text());
$twig->addExtension(new JSUniqueID());
+ $twig->addExtension(new Fit());
$twig->addExtension(new Camelize());
$twig->addExtension(new BytesConverter());
diff --git a/lib/Alchemy/Phrasea/Twig/Fit.php b/lib/Alchemy/Phrasea/Twig/Fit.php
new file mode 100644
index 0000000000..b2ef2fe0dd
--- /dev/null
+++ b/lib/Alchemy/Phrasea/Twig/Fit.php
@@ -0,0 +1,60 @@
+ new \Twig_Function_Method($this, 'fitIn')
+ );
+ }
+
+ public function fitIn(array $content, array $box)
+ {
+ $contentRatio = $content['width'] / $content['height'];
+ $boxRatio = $box['width'] / $box['height'];
+
+ if ($contentRatio > $boxRatio) {
+ if ($box['width'] > $content['width']) {
+ $width = $content['width'];
+ } else {
+ $width = $box['width'];
+ }
+
+ $height = $width / $content['width'] * $content['height'];
+ $top = ($box['height'] - $height) / 2;
+ } else {
+ if ($box['height'] > $content['height']) {
+ $height = $content['height'];
+ } else {
+ $height = $box['height'];
+ }
+
+ $width = $height * $contentRatio;
+ $top = ($box['height'] - $content['height'] / 2);
+ }
+
+ return array(
+ 'width' => round($width),
+ 'height' => round($height),
+ 'top' => round($top)
+ );
+ }
+}
diff --git a/templates/web/common/players/audio.html.twig b/templates/web/common/players/audio.html.twig
new file mode 100644
index 0000000000..09fc62818b
--- /dev/null
+++ b/templates/web/common/players/audio.html.twig
@@ -0,0 +1,21 @@
+{% macro audio_player(thumbnail, url, original_w, original_h, fit) %}
+ {% set random = thumbnail.get_random() %}
+
+
+{% endmacro %}
diff --git a/templates/web/common/players/pdf.html.twig b/templates/web/common/players/pdf.html.twig
new file mode 100644
index 0000000000..e22f84cbed
--- /dev/null
+++ b/templates/web/common/players/pdf.html.twig
@@ -0,0 +1,21 @@
+{% macro pdf_player(thumbnail, url, original_w, original_h, fit) %}
+ {% set random = thumbnail.get_random() %}
+
+
+{% endmacro %}
diff --git a/templates/web/common/players/video.html.twig b/templates/web/common/players/video.html.twig
new file mode 100644
index 0000000000..8455049456
--- /dev/null
+++ b/templates/web/common/players/video.html.twig
@@ -0,0 +1,22 @@
+{% macro video_player(thumbnail, url, original_w, original_h, fit) %}
+ {% set random = thumbnail.get_random %}
+
+
+{% endmacro %}
diff --git a/templates/web/common/thumbnail.html.twig b/templates/web/common/thumbnail.html.twig
index a361faf776..5200055e4c 100644
--- a/templates/web/common/thumbnail.html.twig
+++ b/templates/web/common/thumbnail.html.twig
@@ -1,229 +1,63 @@
-{% macro format(thumbnail, b_w, b_h, extraclass, wrap, lazyload)%}
- {% set record_type = thumbnail.get_type() %}
+{% macro format(thumbnail, box_w, box_h, extra_class, wrap, lazyload) %}
+ {% set record_type = thumbnail.get_type() %}
+ {% set box_w = box_w|round %}
+ {% set box_h = box_h|default(box_w)|round %}
+ {% if record_type == 'AUDIO_MP3' %}
+ {% set original_w = 320 %}
+ {% set original_h = 60 %}
- {% set b_width = b_w %}
- {% set b_height = b_h|default(b_w) %}
-
- {% if record_type == 'AUDIO_MP3' %}
-
- {% set d_width = 320 %}
- {% set d_height = 60 %}
- {% set top = 0 %}
- {% elseif record_type == 'FLEXPAPER' %}
-
- {% set d_width = 800 %}
- {% set d_height = 600 %}
- {% set top = 0 %}
- {% else %}
-
- {% set b_ratio = b_width / b_height %}
-
- {% set thumbnail_height = thumbnail.get_height() > 0 ? thumbnail.get_height() : 120 %}
- {% set thumbnail_width = thumbnail.get_width() > 0 ? thumbnail.get_width() : 120 %}
-
- {% set i_ratio = thumbnail_width / thumbnail_height %}
-
- {% if i_ratio > b_ratio%}
- {% if b_width > thumbnail_width %}
- {% set d_width = thumbnail_width %}
- {% else %}
- {% set d_width = b_width %}
- {% endif %}
- {% set d_height = d_width / thumbnail_width * thumbnail_height %}
- {% set top = (b_height - d_height) / 2 %}
- {% else %}
- {% if b_height > thumbnail_height %}
- {% set d_height = thumbnail_height %}
- {% else %}
- {% set d_height = b_height %}
- {% endif %}
- {% set d_width = d_height * thumbnail_width / thumbnail_height %}
- {% set top = ((b_height - d_height) / 2) %}
- {% endif %}
-
- {% endif %}
-
-
-
- {% if app['authentication'].isAuthenticated() == true %}
- {% set url = thumbnail.get_url() %}
- {% else %}
- {% set url = thumbnail.get_permalink().get_url() %}
- {% endif %}
- {% if wrap %}
-