def get_thumbnail_shim(image, width):
    # This is in its own function because it'll make it easy to add support
    # for other thumbnailers in future. (easy_thumbnails should be easy,
    # and I had it written, but it refuses to work properly with anything that
    # is not an ImageField, i.e. in our test view in views.py.)
    if USE_SORL:
        # Let's do a sorl!
        im = sorl_thumbnail(image, '{}x{}'.format(width, width), upscale=False)
        return im

    # No thumbnailer. :(
    return image
Beispiel #2
0
 def get_thumbnail(self, geometry_string, **kwargs):
     """A shortcut for sorl thumbnail's ``get_thumbnail`` method."""
     for key, value in settings.THUMBNAIL_DEFAULTS.items():
         kwargs.setdefault(key, value)
     if not self.image:
         # Placeholder images
         kwargs.update(settings.PLACEHOLDER_DEFAULTS)
     if geometry_string is None:
         # We have to use django's ImageFile, as sorl-thumbnail's ImageField
         # extends File and not ImageFile, so width property is not
         # available.
         image = ImageFile(self.get_image().file)
         geometry_string = '{}'.format(image.width)
     return sorl_thumbnail(self.get_image(), geometry_string,  **kwargs)
Beispiel #3
0
 def get_thumbnail(self, geometry_string, **kwargs):
     """A shortcut for sorl thumbnail's ``get_thumbnail`` method."""
     for key, value in settings.THUMBNAIL_DEFAULTS.items():
         kwargs.setdefault(key, value)
     if not self.image:
         # Placeholder images
         kwargs.update(settings.PLACEHOLDER_DEFAULTS)
     if geometry_string is None:
         # We have to use django's ImageFile, as sorl-thumbnail's ImageField
         # extends File and not ImageFile, so width property is not
         # available.
         image = ImageFile(self.get_image().file)
         geometry_string = '{}'.format(image.width)
     return sorl_thumbnail(self.get_image(), geometry_string, **kwargs)