Skip to main content

Wagtail Picture Tag adds a picture template tag. This is not supposed to be a solution for all situations but to be a shortcut for most.

It accepts 3 main types of filters: formats, resizing methods and sizes.

Formats

By default it will try and create JPEG, PNG, WEBP and AVIF (if available).

You may use format-jpeg, format-png, format-webp, format-gif and format-avif

There are also two format shortcuts:

  • photo - will create JPEG, WEBP and AVIF

  • transparent - will create WEBP, PNG and AVIF

Resizing

Resizing methods are the same as Wagtails with the exception that you can provide multiple filters

Sizes

Sizes are automatically generated to match resizing filters provided but can be specified for more responsive sizes.

size-250px will create sizes=”250px” size-max100-300vw size-250px will create sizes=”(max-width: 300px) 100vw, 250px”

Lazy

It also takes the argument lazy that simply adds loading=”lazy” to the HTML tag.

AVIF

Currently Willow (the image library used by Wagtail) does not support AVIF but support can be patched in by installing willowavif package.

Quick start

  1. Install the package:

    pip install wagtail-picture-tag
  2. Add “wagtail-picture-tag” to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
        ...
        'wagtail_picture_tag',
    ]
  3. Include the tag in your template:

    {% load picture_tags %}
  4. Use the tag:

    {% picture image photo fill-640x480 fill-320x240 %}

AVIF support

All that is needed is to install the willowavif package, it is then automatically imported and used.

Testing

https://circleci.com/gh/bengosney/wagtail-picture-tag/tree/main.svg?style=svg

Testing is done with pytest. Install and test can be done with:

pip install -r requirements.txt -r requirements.dev.txt
pytest

Release files for wagtail-picture-tag 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wagtail-picture-tag 2.0.1
File Size Uploaded
wagtail-picture-tag-2.0.1.tar.gz 21.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wagtail-picture-tag 2.0.1
File Interpreter ABI Platform
wagtail_picture_tag-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 42.2 kB

Release files / wagtail-picture-tag-2.0.1.tar.gz

Download URL wagtail-picture-tag-2.0.1.tar.gz
Size 21.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0cfd71d03a4b0f5b85d7b0e2fc95f4e942ca2b43f257881c5e04cd21941fa552
BLAKE2b-256 checksum
How to use checksums
b7e2c92e29e074d6c80e12920c58c56a56f4583eb51fc744606bca31884dc128
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.13

Release files / wagtail_picture_tag-2.0.1-py3-none-any.whl

Download URL wagtail_picture_tag-2.0.1-py3-none-any.whl
Size 20.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f8c2f387c7776419470725ac0b4c65713d4e2c1c3f3995e5df6d01a85fcbe8c8
BLAKE2b-256 checksum
How to use checksums
91fc06b0c55da57910c673a2c3a60cb7ccee61d7d17482119719bfb1aa6aa954
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.13

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

2.0.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page