Fix division by 0 in case a thumbnail has a width or height equal to 0

This commit is contained in:
Romain Neutron
2013-12-11 11:44:29 +01:00
parent 0832cc0b21
commit aac9138b18
7 changed files with 86 additions and 47 deletions

View File

@@ -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() %}
<div class="record record_document imgTips" style="width:{{d_width|round}}px;height:{{d_height|round}}px;top:{{top|round}}px;">
<div id="preview_{{thumbnail.get_base_id()}}_{{thumbnail.get_record_id()}}_{{random}}" class="PNB" style=""></div>
<input type="hidden" name="width" value="{{thumbnail.get_width()}}"/>
<input type="hidden" name="height" value="{{thumbnail.get_height()}}"/>
<input type="hidden" name="width" value="{{thumbnail_width}}"/>
<input type="hidden" name="height" value="{{thumbnail_height}}"/>
</div>
<script type="text/javascript">
swfobject.embedSWF("/include/FlexPaper_flash/FlexPaperViewer.swf",
@@ -50,20 +54,20 @@
{% set random = thumbnail.get_random() %}
<div class="record record_audio audioTips" style="width:{{d_width|round}}px;height:{{d_height|round}}px;top:{{top|round}}px;">
<div id="preview_{{thumbnail.get_base_id()}}_{{thumbnail.get_record_id()}}_{{random}}" class="PNB" style=""></div>
<input type="hidden" name="width" value="{{thumbnail.get_width()}}"/>
<input type="hidden" name="height" value="{{thumbnail.get_height()}}"/>
<input type="hidden" name="width" value="{{thumbnail_width}}"/>
<input type="hidden" name="height" value="{{thumbnail_height}}"/>
</div>
<script type="text/javascript">
swfobject.embedSWF("/include/jslibs/audio-player/player.swf",
"preview_{{thumbnail.get_base_id()}}_{{thumbnail.get_record_id()}}_{{random}}",
"{{thumbnail.get_width()}}", "{{thumbnail.get_height()}}", "9.0.0", false, false,
"{{thumbnail_width}}", "{{thumbnail_height}}", "9.0.0", false, false,
{menu: "false",flashvars: "playerID=2&autostart=yes&noinfo=yes&animation=no&remaining=yes&soundFile={{thumbnail.get_url()}}", movie: "/include/jslibs/audio-player/player.swf", allowFullScreen :"true",wmode: "transparent"}, false);</script>
{% else %}
<img class="record record_image imgTips zoomable thumb" oncontextMenu="return(false);"
style="width:{{d_width|round}}px;height:{{d_height|round}}px;top:{{top|round}}px;"
src="{{thumbnail.get_url()}}" ondragstart="return false;">
<input type="hidden" name="width" value="{{thumbnail.get_width()}}"/>
<input type="hidden" name="height" value="{{thumbnail.get_height()}}"/>
<input type="hidden" name="width" value="{{thumbnail_width}}"/>
<input type="hidden" name="height" value="{{thumbnail_height}}"/>
{% endif %}
</div>

View File

@@ -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 = {

View File

@@ -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() %}
<div class="record record_video imgTips" style="position:relative;width:{{d_width|round}}px;height:{{d_height|round}}px;top:{{top|round}}px;">
<div id="preview{{random}}" class="PNB"></div>
<input type="hidden" name="width" value="{{thumbnail.get_width()}}"/>
<input type="hidden" name="height" value="{{thumbnail.get_height()}}"/>
<input type="hidden" name="width" value="{{thumbnail_width}}"/>
<input type="hidden" name="height" value="{{thumbnail_height}}"/>
</div>
<script type="text/javascript">
flowplayer("preview{{random}}",
@@ -82,8 +86,8 @@
{% set random = thumbnail.get_random() %}
<div class="record record_audio audioTips" style="width:{{d_width|round}}px;height:{{d_height|round}}px;top:{{top|round}}px;">
<div id="preview_{{thumbnail.get_sbas_id()}}_{{thumbnail.get_record_id()}}_{{random}}" class="PNB" style=""></div>
<input type="hidden" name="width" value="{{thumbnail.get_width()}}"/>
<input type="hidden" name="height" value="{{thumbnail.get_height()}}"/>
<input type="hidden" name="width" value="{{thumbnail_width}}"/>
<input type="hidden" name="height" value="{{thumbnail_height}}"/>
</div>
<script type="text/javascript">
swfobject.embedSWF("/include/jslibs/audio-player/player.swf",
@@ -94,8 +98,8 @@
<img class="{% if lazyload %}lazyload{% endif %} record record_image imgTips zoomable thumb" oncontextMenu="return(false);"
style="width:{{d_width|round}}px;height:{{d_height|round}}px;top:{{top|round}}px;"
src="{% if lazyload %}/skins/grey.gif{% else %}{{ url }}{% endif %}" data-original="{{ url }}" ondragstart="return false;">
<input type="hidden" name="width" value="{{thumbnail.get_width()}}"/>
<input type="hidden" name="height" value="{{thumbnail.get_height()}}"/>
<input type="hidden" name="width" value="{{thumbnail_width}}"/>
<input type="hidden" name="height" value="{{thumbnail_height}}"/>
{% endif %}
{% if wrap %}
</div>
@@ -125,19 +129,23 @@
{% 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%}
{% set d_height = b_height %}
{% set d_width = d_height * thumbnail.get_width() / thumbnail.get_height() %}
{% set d_width = d_height * thumbnail_width / thumbnail_height %}
{% set left = (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 %}
@@ -157,8 +165,8 @@
{% set random = thumbnail.get_random() %}
<div class="record record_video imgTips" style="position:relative;width:{{d_width|round}}px;height:{{d_height|round}}px;top:{{top|round}}px;">
<div id="preview{{random}}" class="PNB"></div>
<input type="hidden" name="width" value="{{thumbnail.get_width()}}"/>
<input type="hidden" name="height" value="{{thumbnail.get_height()}}"/>
<input type="hidden" name="width" value="{{thumbnail_width}}"/>
<input type="hidden" name="height" value="{{thumbnail_height}}"/>
</div>
<script type="text/javascript">
flowplayer("preview{{random}}",
@@ -183,8 +191,8 @@
{% set random = thumbnail.get_random() %}
<div class="record record_audio audioTips" style="width:{{d_width|round}}px;height:{{d_height|round}}px;top:{{top|round}}px;">
<div id="preview_{{thumbnail.get_sbas_id()}}_{{thumbnail.get_record_id()}}_{{random}}" class="PNB" style=""></div>
<input type="hidden" name="width" value="{{thumbnail.get_width()}}"/>
<input type="hidden" name="height" value="{{thumbnail.get_height()}}"/>
<input type="hidden" name="width" value="{{thumbnail_width}}"/>
<input type="hidden" name="height" value="{{thumbnail_height}}"/>
</div>
<script type="text/javascript">
swfobject.embedSWF("/include/jslibs/audio-player/player.swf",
@@ -195,8 +203,8 @@
<img class="record record_image imgTips zoomable thumb" oncontextMenu="return(false);"
style="width:{{d_width|round}}px;height:{{d_height|round}}px;top:{{top|round}}px;"
src="{{url}}" ondragstart="return false;">
<input type="hidden" name="width" value="{{thumbnail.get_width()}}"/>
<input type="hidden" name="height" value="{{thumbnail.get_height()}}"/>
<input type="hidden" name="width" value="{{thumbnail_width}}"/>
<input type="hidden" name="height" value="{{thumbnail_height}}"/>
{% endif %}
{% if wrap %}
</div>
@@ -204,3 +212,4 @@
{% endmacro %}

View File

@@ -69,10 +69,18 @@
{% set thumbnail = record.get_thumbnail() %}
{% if thumbnail.is_paysage() %}
{% set w = 140 %}
{% set h = (w / (thumbnail.get_width() / thumbnail.get_height()))|round %}
{% if thumbnail.get_height() > 0 and thumbnail.get_width() > 0 %}
{% set h = (w / (thumbnail.get_width() / thumbnail.get_height()))|round %}
{% else %}
{% set h = 140 %}
{% endif %}
{% else %}
{% set h = 105 %}
{% set w = (h * (thumbnail.get_width() / thumbnail.get_height()))|round %}
{% if thumbnail.get_height() > 0 %}
{% set w = (h * (thumbnail.get_width() / thumbnail.get_height()))|round %}
{% else %}
{% set w = 105 %}
{% endif %}
{% endif %}
<img width="{{ w ~ 'px' }}" height="{{ h ~ 'px' }}" src="{{ thumbnail.get_url() }}" />

View File

@@ -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 %}

View File

@@ -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 %}

View File

@@ -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 %}