renditions.rst 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. .. _image_renditions:
  2. Generating renditions in Python
  3. =====================================
  4. Rendered versions of original images generated by the Wagtail ``{% image %}`` template tag are called "renditions",
  5. and are stored as new image files in the site's ``[media]/images`` directory on the first invocation.
  6. Image renditions can also be generated dynamically from Python via the native ``get_rendition()`` method, for example:
  7. .. code-block:: python
  8. newimage = myimage.get_rendition('fill-300x150|jpegquality-60')
  9. If ``myimage`` had a filename of ``foo.jpg``, a new rendition of the image file called
  10. ``foo.fill-300x150.jpegquality-60.jpg`` would be generated and saved into the site's ``[media]/images`` directory.
  11. Argument options are identical to the ``{% image %}`` template tag's filter spec, and should be separated with ``|``.
  12. The generated ``Rendition`` object will have properties specific to that version of the image, such as
  13. ``url``, ``width`` and ``height``, so something like this could be used in an API generator, for example:
  14. .. code-block:: python
  15. url = myimage.get_rendition('fill-300x186|jpegquality-60').url
  16. Properties belonging to the original image from which the generated Rendition was created, such as ``title``, can
  17. be accessed through the Rendition's ``image`` property:
  18. .. code-block:: python
  19. >>> newimage.image.title
  20. 'Blue Sky'
  21. >>> newimage.image.is_landscape()
  22. True
  23. See also: :ref:`image_tag`