- Install easy-thumbnails for django
- make folder templatetags in app containing empty
__init__.py
and is_portrait.py - use filter in django template
Last active
August 29, 2015 14:24
-
-
Save martinkrung/dc57f62eb030de47ffe9 to your computer and use it in GitHub Desktop.
template filter for django easy-thumbnails image orientation check (is_portrait)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from django import template | |
register = template.Library() | |
@register.filter(is_safe=True) | |
def is_portrait(im): | |
if im.image.height > im.image.width: | |
return True | |
else: | |
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% load is_portrait %} | |
{% load thumbnail %} | |
{% if textmedia.image|is_portrait %} | |
{% thumbnail textmedia.image "360x2000" upscale=False as thumb %} | |
<img src="{{ thumb.url }}" alt="{{ textmedia.image.default_caption }}"><br> | |
{% if textmedia.default_caption %}<span class="acaption">{{ textmedia.image.default_caption }}</span><br>{% endif %} | |
{% else %} | |
{% thumbnail textmedia.image "580x2000" upscale=False as thumb %} | |
<img src="{{ thumb.url }}" alt="{{ textmedia.image.default_caption }}"><br> | |
{% if textmedia.default_caption %}<span class="acaption">{{ textmedia.image.default_caption }}</span><br>{% endif %} | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment