From aac9138b184db4ab1885930f2c6881f9582683c4 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Wed, 11 Dec 2013 11:44:29 +0100 Subject: [PATCH] Fix division by 0 in case a thumbnail has a width or height equal to 0 --- templates/mobile/common/thumbnail.html.twig | 32 ++++++----- .../client/home_inter_pub_basket.html.twig | 8 ++- templates/web/common/thumbnail.html.twig | 57 +++++++++++-------- .../prod/actions/Download/prepare.html.twig | 14 ++++- .../web/prod/preview/basket_train.html.twig | 6 +- .../web/prod/preview/feed_train.html.twig | 8 ++- .../web/prod/preview/reg_train.html.twig | 8 ++- 7 files changed, 86 insertions(+), 47 deletions(-) diff --git a/templates/mobile/common/thumbnail.html.twig b/templates/mobile/common/thumbnail.html.twig index 537e608cef..e3854a2772 100644 --- a/templates/mobile/common/thumbnail.html.twig +++ b/templates/mobile/common/thumbnail.html.twig @@ -3,23 +3,27 @@ {% set b_height = b_h|default(b_w) %} {% set b_ratio = b_width / b_height %} - {% set i_ratio = thumbnail.get_width() / thumbnail.get_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.get_width() %} - {% set d_width = thumbnail.get_width() %} + {% if b_width > thumbnail_width %} + {% set d_width = thumbnail_width %} {% else %} {% set d_width = b_width %} {% endif %} - {% set d_height = d_width / thumbnail.get_width() * thumbnail.get_height() %} + {% set d_height = d_width / thumbnail_width * thumbnail_height %} {% set top = (b_height - d_height) / 2 %} {% else %} - {% if b_height > thumbnail.get_height() %} - {% set d_height = thumbnail.get_height() %} + {% if b_height > thumbnail_height %} + {% set d_height = thumbnail_height %} {% else %} {% set d_height = b_height %} {% endif %} - {% set d_width = d_height * thumbnail.get_width() / thumbnail.get_height() %} + {% set d_width = d_height * thumbnail_width / thumbnail_height %} {% set top = ((b_height - d_height) / 2) %} {% endif %} @@ -37,8 +41,8 @@ {% set random = thumbnail.get_random() %}
- - + +
{% else %} - - + + {% endif %} diff --git a/templates/web/client/home_inter_pub_basket.html.twig b/templates/web/client/home_inter_pub_basket.html.twig index 225a7e7a99..dfc0985325 100644 --- a/templates/web/client/home_inter_pub_basket.html.twig +++ b/templates/web/client/home_inter_pub_basket.html.twig @@ -43,7 +43,13 @@ {% set thumbnail = record.get_thumbnail() %} {% set docType = record.get_type() %} {% set duration = "" %} - {% set ratio = thumbnail.get_width() / thumbnail.get_height() %} + + {% if thumbnail.get_height() > 0 %} + {% set ratio = thumbnail.get_width() / thumbnail.get_height() %} + {% else %} + {% set ratio = 1 %} + {% endif %} + {% set wrapper_size = image_size + 30 %} {% set types = { diff --git a/templates/web/common/thumbnail.html.twig b/templates/web/common/thumbnail.html.twig index b91a64137f..4a5f265e8e 100644 --- a/templates/web/common/thumbnail.html.twig +++ b/templates/web/common/thumbnail.html.twig @@ -18,23 +18,27 @@ {% else %} {% set b_ratio = b_width / b_height %} - {% set i_ratio = thumbnail.get_width() / thumbnail.get_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.get_width() %} - {% set d_width = thumbnail.get_width() %} + {% if b_width > thumbnail_width %} + {% set d_width = thumbnail_width %} {% else %} {% set d_width = b_width %} {% endif %} - {% set d_height = d_width / thumbnail.get_width() * thumbnail.get_height() %} + {% set d_height = d_width / thumbnail_width * thumbnail_height %} {% set top = (b_height - d_height) / 2 %} {% else %} - {% if b_height > thumbnail.get_height() %} - {% set d_height = thumbnail.get_height() %} + {% if b_height > thumbnail_height %} + {% set d_height = thumbnail_height %} {% else %} {% set d_height = b_height %} {% endif %} - {% set d_width = d_height * thumbnail.get_width() / thumbnail.get_height() %} + {% set d_width = d_height * thumbnail_width / thumbnail_height %} {% set top = ((b_height - d_height) / 2) %} {% endif %} @@ -54,8 +58,8 @@ {% set random = thumbnail.get_random() %}
- - + +
-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/templates/web/prod/preview/basket_train.html.twig b/templates/web/prod/preview/basket_train.html.twig index 5ac250418d..410e42ba34 100644 --- a/templates/web/prod/preview/basket_train.html.twig +++ b/templates/web/prod/preview/basket_train.html.twig @@ -5,7 +5,11 @@ {% set thumbnail = child.getRecord(app).get_thumbnail() %} {% if thumbnail.is_paysage() %} {% set style = 'width:65px;top:' %} - {% set top = ((66 - (65 / (thumbnail.get_width() / thumbnail.get_height()))) / 2)|round %} + {% if thumbnail.get_width() > 0 and thumbnail.get_height() > 0 %} + {% set top = ((66 - (65 / (thumbnail.get_width() / thumbnail.get_height()))) / 2)|round %} + {% else %} + {% set top = 65 %} + {% endif %} {% set style = style ~ top %} {% set style = style ~ 'px;' %} {% else %} diff --git a/templates/web/prod/preview/feed_train.html.twig b/templates/web/prod/preview/feed_train.html.twig index d9d44f0b9a..a91a2ce064 100644 --- a/templates/web/prod/preview/feed_train.html.twig +++ b/templates/web/prod/preview/feed_train.html.twig @@ -5,7 +5,11 @@ {% set thumbnail = child.get_record().get_thumbnail() %} {% if thumbnail.is_paysage() %} {% set style = 'width:65px;top:' %} - {% set top = ((66 - (65 / (thumbnail.get_width() / thumbnail.get_height()))) / 2)|round %} + {% if thumbnail.get_width() > 0 and thumbnail.get_height() > 0 %} + {% set top = ((66 - (65 / (thumbnail.get_width() / thumbnail.get_height()))) / 2)|round %} + {% else %} + {% set top = 65 %} + {% endif %} {% set style = style ~ top %} {% set style = style ~ 'px;' %} {% else %} @@ -40,4 +44,4 @@
{% include 'prod/preview/tools.html.twig' %} -
\ No newline at end of file + diff --git a/templates/web/prod/preview/reg_train.html.twig b/templates/web/prod/preview/reg_train.html.twig index 7567305393..666f0ee481 100644 --- a/templates/web/prod/preview/reg_train.html.twig +++ b/templates/web/prod/preview/reg_train.html.twig @@ -2,7 +2,11 @@ {% set regroupement = record.get_container() %} {% set thumbnail = regroupement.get_thumbnail() %} - {% set ratio = thumbnail.get_width() / thumbnail.get_height() %} + {% if thumbnail.get_height() > 0 %} + {% set ratio = thumbnail.get_width() / thumbnail.get_height() %} + {% else %} + {% set ratio = 1 %} + {% endif %} {% if thumbnail.is_paysage %} {% set style = 'width:80px;top:' %} {% set top = (8 + (80 - (80 / ratio)) / 2)|round %} @@ -59,4 +63,4 @@
{% include 'prod/preview/tools.html.twig' %} -
\ No newline at end of file +