A wagtail plugin that generates tiny blurry placeholder images for lazy-loading.
Project description
Wagtail Lazy Images
A plugin to automatically generate tiny blurry placeholder images for your wagtail images in order to lazy-load them medium.com style.
Installing
Install using pip:
pip install wagtail-lazyimages
Usage
-
Add
wagtail_lazyimagesto yourINSTALLED_APPSsetting like this:INSTALLED_APPS = [ ... 'wagtail_lazyimages', ] -
Load the
lazyimages_tagstemplate tag library in your template:{% load "lazyimages_tags" %} -
Replace wagtail's
imagetag withlazy_imagefor images that should lazy load:{% lazy_image page.photo width-960 class="lazy" %}This template tag behaves exactly the same way as the
imagestag with the exception that it generates an additional small and blurred image. The URL of this image will appear in thesrcattribute of the image while the larger version will be referenced indata-src:<img src="/path/to/placeholder-image.jpg" data-src"/path/to/image.jpg" class="lazy" /> -
In the front end: Implement the lazy loading functionality yourself or use a dedicated JavaScript library like lozad.js:
const observer = lozad('.lazy'); observer.observe();
Image in context variable
If you need to assign the image data to a template variable using Django's as syntax, use the provided filter for the placeholder image URL:
{% load "lazyimages_tags" %}
{% image page.photo width-960 as img %}
<img data-src="{{ img.url }}" src="{{ img|lazy_url }}" width="{{ img.width }}"
height="{{ img.height }}" alt="{{ img.alt }}" />
Alternative attribute
If you want to use a different attribute for referencing the original image than data-src use the parameter lazy_attr for that:
{% lazy_image page.photo width-960 lazy_attr="data-lazy-url" class="lazy" %}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file wagtail-lazyimages-0.1.tar.gz.
File metadata
- Download URL: wagtail-lazyimages-0.1.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10daa58daea5f8b12bd0a2ef8ce4559ead2c427f459b7dfca29a27e2fc3a889d
|
|
| MD5 |
73a3c29c92c6b503acb67790a0ba8296
|
|
| BLAKE2b-256 |
8bd6895a29927738ecdf2951b5dff3b2b9c17139937ef2894fa4c90d888e98c3
|