Пример #1
0
def img(src, width=None, height=None, method=PROPORTIONAL, alt="", **attrs):
    """Renders an image tag."""
    params = {
        "alt": alt,
        "attrs": attrs,
    }
    try:
        thumbnail = default_thumbnail_cache.get_thumbnail(
            src,
            width = width,
            height = height,
            method = method,
        )
    except ThumbnailError:
        asset = AdaptiveAsset(src)
        params.update({
            "url": asset.get_url(),
            "width": width or "",
            "height": height or "",
        })
    else:
        params.update({
            "url": thumbnail.url,
            "width": thumbnail.width,
            "height": thumbnail.height,

        })
    return params
Пример #2
0
def img(src, width=None, height=None, method=PROPORTIONAL, alt="", **attrs):
    """Renders an image tag."""
    params = {
        "alt": alt,
        "attrs": attrs,
    }
    try:
        thumbnail = default_thumbnail_cache.get_thumbnail(
            src,
            width=width,
            height=height,
            method=method,
        )
    except ThumbnailError:
        asset = AdaptiveAsset(src)
        params.update({
            "url": asset.get_url(),
            "width": width or "",
            "height": height or "",
        })
    else:
        params.update({
            "url": thumbnail.url,
            "width": thumbnail.width,
            "height": thumbnail.height,
        })
    return params
Пример #3
0
def video_img(src, width, height, method=VIDEO_PROPORTIONAL, alt="", **attrs):
    """Renders an image tag from the given video."""
    params = {
        "alt": alt,
        "attrs": attrs,
        "width": width,
        "height": height,
    }
    try:
        url = default_video_cache.get_url(src, width, height, method, format=JPEG_FORMAT)
    except VideoError:
        asset = AdaptiveAsset(src)
        url = asset.get_url()
    params["url"] = url
    return params
Пример #4
0
def video_img(src, width, height, method=VIDEO_PROPORTIONAL, alt="", **attrs):
    """Renders an image tag from the given video."""
    params = {
        "alt": alt,
        "attrs": attrs,
        "width": width,
        "height": height,
    }
    try:
        url = default_video_cache.get_url(src,
                                          width,
                                          height,
                                          method,
                                          format=JPEG_FORMAT)
    except VideoError:
        asset = AdaptiveAsset(src)
        url = asset.get_url()
    params["url"] = url
    return params
def responsive_img(src, method=PROPORTIONAL, alt="", **attrs):
    """Renders an image tag."""
    output = {
        "sizes": [],
        "alt": alt,
        "attrs": attrs,
    }

    for size in settings.RESPONSIVE_IMAGES_SIZES:
        params = {}

        try:
            thumbnail = default_thumbnail_cache.get_thumbnail(
                src,
                width=size['width'],
                height=size['height'],
                method=method,
            )
        except ThumbnailError:
            asset = AdaptiveAsset(src)
            params.update({
                "url": asset.get_url(),
                "width": size['width'] or "",
                "height": size['height'] or "",
            })
        else:
            params.update({
                "url": thumbnail.url,
                "width": thumbnail.width,
                "height": thumbnail.height,

            })

        output['sizes'].append(params)

    return output
Пример #6
0
    def get_thumbnail(self,
                      asset,
                      width=None,
                      height=None,
                      method=PROPORTIONAL):
        """
        Returns a thumbnail of the given size.

        Either or both of width and height may be None, in which case the
        image's original size will be used.
        """
        # Lookup the method.
        try:
            method = _methods[method]
        except KeyError:
            raise ValueError(
                "{method} is not a valid thumbnail method. Should be one of {methods}."
                .format(method=method, methods=", ".join(_methods.keys())))
        # Adapt the asset.
        asset = AdaptiveAsset(asset)
        # Create the thumbnail.
        return Thumbnail(self._asset_cache,
                         ThumbnailAsset(asset, width, height, method))
 def _get_video_asset(self, asset, width=None, height=None, method=PAD, format=MP4_FORMAT, offset=None):
     """
     Returns a processed video from the given video.
     """
     # Lookup the method.
     try:
         method = _methods[method]
     except KeyError:
         raise ValueError("{method} is not a valid video method. Should be one of {methods}.".format(
             method = method,
             methods = ", ".join(_methods.keys())
         ))
     # Lookup the format.
     try:
         format = _formats[format]
     except KeyError:
         raise ValueError("{format} is not a valid video format. Should be one of {formats}.".format(
             format = format,
             formats = ", ".join(_formats.keys())
         ))
     # Adapt the asset.
     asset = AdaptiveAsset(asset)
     # Create the video.
     return VideoAsset(asset, width, height, method, format, offset)