image_file_formats.rst 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. .. _image_file_formats:
  2. Image file formats
  3. ==================
  4. Using the picture element
  5. -------------------------
  6. The `picture element <https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture>`_
  7. can be used with the ``format-<type>`` image operation to specify different
  8. image formats and let the browser choose the one it prefers. For example:
  9. .. code-block:: python
  10. {% load wagtailimages_tags %}
  11. <picture>
  12. {% image myimage width-1000 format-webp as image_webp %}
  13. <source srcset="{{ image_webp.url }}" type="image/webp">
  14. {% image myimage width-1000 format-png as image_png %}
  15. <source srcset="{{ image_png.url }}" type="image/png">
  16. {% image myimage width-1000 format-png %}
  17. </picture>
  18. Customizing output formats
  19. --------------------------
  20. By default all ``bmp`` and ``webp`` images are converted to the ``png`` format
  21. when no image output format is given.
  22. The default conversion mapping can be changed by setting the
  23. ``WAGTAILIMAGES_FORMAT_CONVERSIONS`` to a dictionary which maps the input type
  24. to an output type.
  25. For example:
  26. .. code-block:: python
  27. WAGTAILIMAGES_FORMAT_CONVERSIONS = {
  28. 'bmp': 'jpeg',
  29. 'webp': 'webp',
  30. }
  31. will convert ``bmp`` images to ``jpeg`` and disable the default ``webp``
  32. to ``png`` conversion.