djblets.util.templatetags.djblets_images¶
Image-related template tags.
- save_image_to_storage(image, storage, filename)¶
Save an image to storage.
- crop_image(f, x, y, width, height)¶
Crops an image at the specified coordinates and dimensions, returning the resulting URL of the cropped image.
- thumbnail(f, size='400x100')¶
Create a thumbnail of the given image.
This will create a thumbnail of the given
file
(a Django FileField or ImageField) with the given size. Size can either be a string of WxH (in pixels), or a 2-tuple. If the size is a tuple and the second part is None, it will be calculated to preserve the aspect ratio.If the image format is not registered in PIL the thumbnail is not generated and returned as-is.
This will return the URL to the stored thumbnail.
- build_srcset(sources)¶
Return the source set attribute value for the given sources.
The resulting sources will be sorted by value, with the pixel density (
x
) values coming before width (w
) values.
- srcset(sources)¶
Render the source set attribute value for the given sources.
The resulting sources will be sorted by value, with the pixel density (
x
) values coming before width (w
) values.
- image_source_attrs(context, nodelist, *options)¶
Render source attributes for an image tag.
This will render
src="..." srcset="..."
attributes for an<img>
tag, based on the sources provided in the tag’s content. There should be one source definition per line (with an optional trailing comma) in the form of:<descriptor> <URL>
These will get turned into a
srcset
, and the1x
descriptor (which is required) will be set as thesrc
attribute.- Parameters:
block_content (
unicode
) – The block content containing image sources.- Returns:
Attributes for the
<img>
tag.
Example
<img {% image_source_attrs %} 1x {% static "images/myimage.png" %} 2x {% static "images/myimage@2x.png" %} 3x {% static "images/myimage@3x.png" %} {% end_image_source_attrs %}>