0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-29 17:36:49 +01:00
wagtail/docs/advanced_topics/images/renditions.rst
Storm Heg 24ef0e62e6 Fix documentation indentation
Fix code block indentation in tutorial.rst

Prevent it from being displayed as a quote.

Fix indentation in pages.rst

Fix indentation in indexing.rst

Fix indentation in searching.rst

Fix indentation in backends.rst

Fix indentation in renditions.rst

Fix indentation in custom_image_model.rst

Fix indentation in feature_detection.rst

Fix indentation in image_serve_view.rst

Fix indentation in custom_document_model.rst

Fix indentation in i18n.rst

Fix indentation in privacy.rst

Fix indentation in page_editing_interface.rst

Fix indentation in rich_text_internals.rst

Fix indentation in extending_hallo.rst

Fix indentation in configuration.rst

Fix indentation in usage.rst

Fix indentation in theory.rst

Fix indentation in model_reference.rst

Fix indentation in queryset_reference.rst

Configure editors to indent .rst files with 2 spaces

In order for the documentation to be styled correctly, the generator
depends on indentation. Too much indentation can result in the content
being wrapped in a quote block, which looks bad.

Fix indentation in sitemaps.rst

Fix indentation in frontendcache.rst

Fix indentation in routablepage.rst

Fix indentation in table_block.rst

Fix routablepage.rst autodocs disppearing

Fix indentation in table_block.rst

Fix indentation in redirects.rst

Fix indentation in table_documentation-modes.rst

Fix indentation in browser_issues.rst

Fix indentation in release_process.rst

Fix indentation of release notes

One more indent fix in the release notes

Fix indentation warnings

Fix warning about undefined label in docs

Error during `make html`:

  wagtail/docs/releases/1.7.rst:25: WARNING: undefined label: jpeg_image_quality
2021-02-26 09:17:00 +00:00

37 lines
1.4 KiB
ReStructuredText

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