diff options
author | luxagraf <sng@luxagraf.net> | 2017-01-01 16:15:59 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2017-01-01 16:15:59 -0500 |
commit | 3a876c9382c6e617f6dfebc087cbd89154c8ce78 (patch) | |
tree | 043aeac62181f461711ef159f17097ed9c3f8479 | |
parent | a87323ebd04782a41e3e808f31f6b893b47f4610 (diff) |
fixed picful template
-rw-r--r-- | app/photos/templatetags/get_image_width.py | 9 | ||||
-rw-r--r-- | design/templates/lib/img_picfull.html | 5 |
2 files changed, 12 insertions, 2 deletions
diff --git a/app/photos/templatetags/get_image_width.py b/app/photos/templatetags/get_image_width.py new file mode 100644 index 0000000..ac39184 --- /dev/null +++ b/app/photos/templatetags/get_image_width.py @@ -0,0 +1,9 @@ +from math import floor +from django import template + +register = template.Library() + +@register.simple_tag +def get_image_width(obj, size, *args): + ratio = floor(int(size)*100/int(obj.height))/100 + return floor(ratio*int(obj.height)) diff --git a/design/templates/lib/img_picfull.html b/design/templates/lib/img_picfull.html index 484cde4..bc7a6a8 100644 --- a/design/templates/lib/img_picfull.html +++ b/design/templates/lib/img_picfull.html @@ -1,8 +1,9 @@ {% load get_image_by_size %} +{% load get_image_width %} {% if caption %} <figure class="picfull">{%endif%} - <a href="{%get_image_by_size image "original"%} " title="view larger image"><img class="picfull" sizes="(max-width: 680px) 100vw, (min-width: 681) 680px" srcset="{% for size in image.sizes.all%}{% get_image_by_size image size.name %} {% if size.width %}{{size.width}}{%else%}{{size.height}}w{%endif%}{% if forloop.last%}"{%else%}, {%endif%}{%endfor%} +<a href="{%get_image_by_size image "original"%} " title="view larger image"><img class="picfull" sizes="(max-width: 680px) 100vw, (min-width: 681) 680px" srcset="{% for size in image.sizes.all%}{% get_image_by_size image size.name %} {% if image.is_portait %}{% get_image_width image size.height %}{%else%}{{size.width}}w{%endif%}{% if forloop.last%}"{%else%}, {%endif%}{%endfor%} {% for size in image.sizes.all%}{%if forloop.first %} src="{% get_image_by_size image size.name %}"{%endif%}{%endfor%} alt="{{image.alt}} photographed by {% if image.photo_credit_source %}{{image.photo_credit_source}}{%else%}luxagraf{%endif%}" data-jslghtbx="{%get_image_by_size image "original"%}" data-jslghtbx-group="group" {% if caption%}data-jslghtbx-caption="{{image.caption}}"{%endif%}></a> - {% if caption %}<figcaption>{{image.caption|safe}}</figcaption> +{% if caption %}<figcaption>{{image.caption|safe}}</figcaption> </figure> {% endif %} |