Beispiel #1
0
def get_thumb(context, img, w=None, h=None):

    if not img:
        # we must provide path to a static file as a fully qualified external,
        # because sorl.thumbnail forces MEDIA_URL to be the one true source
        img = context['request'].build_absolute_uri(
            '{static}img/holder_{choice}.png'.format(
                static=settings.STATIC_URL,
                choice=random.choice(['01', '02', '03']),
            ))

    assert w or h
    h = h or w
    size = '{w}{h}'.format(w=w * 2 if w else '', h='x' + str(h * 2))

    options = dict(
        # crop 20% to the top if size is landscape or square and source is portrait
        crop='20%' if w >= h and is_portrait(img) else 'center',
        quality=40,
        format='JPEG',
        upscale=True,
    )

    return get_thumbnail(img, size, **options).url
Beispiel #2
0
 def thumb_medium(self):
     if is_portrait(self.file):
         return self.thumb(geometry_string='x400')
     else:
         return self.thumb(geometry_string='400')
Beispiel #3
0
 def thumb_medium(self):
     if is_portrait(self.file):
         return self.thumb(geometry_string='x400')
     else:
         return self.thumb(geometry_string='400')
Beispiel #4
0
 def thumb_big(self):
     if is_portrait(self.file):
         return self.thumb(geometry_string='x800')
     else:
         return self.thumb(geometry_string='800')
Beispiel #5
0
 def thumb_big(self):
     if is_portrait(self.file):
         return self.thumb(geometry_string='x800')
     else:
         return self.thumb(geometry_string='800')