2022-05-26 15:24:47 +02:00
|
|
|
(image_file_formats)=
|
|
|
|
|
|
|
|
# Image file formats
|
|
|
|
|
|
|
|
## Using the picture element
|
|
|
|
|
|
|
|
The [picture element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture)
|
|
|
|
can be used with the `format-<type>` image operation to specify different
|
|
|
|
image formats and let the browser choose the one it prefers. For example:
|
|
|
|
|
|
|
|
```python
|
|
|
|
{% load wagtailimages_tags %}
|
|
|
|
|
|
|
|
<picture>
|
2023-07-13 20:20:26 +02:00
|
|
|
{% image myimage width-1000 format-avif as image_avif %}
|
|
|
|
<source srcset="{{ image_avif.url }}" type="image/avif">
|
|
|
|
|
2022-05-26 15:24:47 +02:00
|
|
|
{% image myimage width-1000 format-webp as image_webp %}
|
|
|
|
<source srcset="{{ image_webp.url }}" type="image/webp">
|
|
|
|
|
|
|
|
{% image myimage width-1000 format-png as image_png %}
|
|
|
|
<source srcset="{{ image_png.url }}" type="image/png">
|
|
|
|
|
|
|
|
{% image myimage width-1000 format-png %}
|
|
|
|
</picture>
|
|
|
|
```
|
|
|
|
|
|
|
|
### Customising output formats
|
|
|
|
|
2023-07-13 20:20:26 +02:00
|
|
|
By default, all `avif`, `bmp` and `webp` images are converted to the `png` format
|
2022-05-26 15:24:47 +02:00
|
|
|
when no image output format is given.
|
|
|
|
|
|
|
|
The default conversion mapping can be changed by setting the
|
2022-10-21 01:30:13 +02:00
|
|
|
`WAGTAILIMAGES_FORMAT_CONVERSIONS` to a dictionary, which maps the input type
|
2022-05-26 15:24:47 +02:00
|
|
|
to an output type.
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
```python
|
|
|
|
WAGTAILIMAGES_FORMAT_CONVERSIONS = {
|
2023-07-13 20:20:26 +02:00
|
|
|
'avif': 'avif',
|
2022-05-26 15:24:47 +02:00
|
|
|
'bmp': 'jpeg',
|
|
|
|
'webp': 'webp',
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2023-07-13 20:20:26 +02:00
|
|
|
will convert `bmp` images to `jpeg` and disable the default `avif` and `webp`
|
2022-05-26 15:24:47 +02:00
|
|
|
to `png` conversion.
|