Returns a webp image instead of jpg, gif or png to browsers which have support
Project description
Returns a webp image instead of jpg, gif or png to browsers which have support.
Usage
Load the webp module in your template and use the webp templatetag to point to the image you want to convert.
{% load webp %}
{# Use webp as you would use static templatetag #}
<img src="{% webp 'path/to/your/image.png' %}" alt="image" />
<!--
If the browser has support, generates:
<img src="/static/WEBP_CACHE/path/to/your/image.webp" alt="image" />
else, generates:
<img src="/static/path/to/your/image.png" alt="image" />
-->
Installation
First of all, you must install the webp support. In ubuntu you can install via apt-get:
apt-get install libwebp-dev
Please, check the official guide for the other systems.
Then, install django-webp.
pip install django-webp
add it to INSTALLED_APPS configuration
INSTALLED_APPS = (
'django.contrib.staticfiles',
'django_webp',
'...',
)
add the django_webp context processor
TEMPLATES = [
{
'...'
'OPTIONS': {
'context_processors': [
'...',
'django_webp.context_processors.webp',
],
},
},
]
Possible problems
django-webp uses Pillow to convert the images. If you’ve installed the libwebp-dev after already installed Pillow, it’s necessary to uninstall and install it back because it needs to be compiled with it.
Cleaning the cache
You can clean the cache running:
python manage.py clean_webp_images
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 Distributions
Built Distributions
Hashes for django_webp-2.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9eaebb28502d0031b666a8704c29db4836df9b15d59cfe35848465e6fdbcfc5d |
|
MD5 | e0615929dc61260d810b8cdbc00ca587 |
|
BLAKE2b-256 | cfdcce25d614bfae00db930b90e2fc13dac7e020b0248af8c624533746f1f351 |
Hashes for django_webp-2.0.0-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9d62c86544635f095fc286fd104fa4cdf5a2dfef37bf9ec5a92ddca449e78f1 |
|
MD5 | 45c829518dafd2b11a0d8d0aa213a63d |
|
BLAKE2b-256 | 02b4e4183da1eec255fe4e941c38bc2bf878f786dd30652342f42751c4fea8c1 |