• 
      

    Add options for more control over image thumbnailing.

    Review Request #13869 — Created May 20, 2024 and submitted — Latest diff uploaded

    Information

    Djblets
    release-5.x

    Reviewers

    The {% thumbnail %} template filter has been around a long time, and
    has remained pretty static in that time. It took in a FileField-backed
    file instance, a WIDTHxHEIGHT string or (width, height) tuple (with
    an optional height), and generated a thumbnail if one didn't exist.

    It wasn't able to work with arbitrary File instances or file paths in
    a storage backend, couldn't build an aspect ratio around just a height,
    or tell us the path of a thumbnail without first generating it. And the
    code was playing it fast and loose with input types.

    This change modernizes much of this method. It's now type-safe, capable
    of working with a range of input types representing files, and
    sanity-checks the files and sizes for validity.

    It can now cap to either a width or to a height, maintaining aspect
    ratio.

    It can be told not to create a thumbnail if it doesn't already exist,
    helping to retrieve the URL to a thumbnail in order to, say, delete it,
    without doing the work of uselessly creating one first.

    Unit tests were added to check all thumbnailing functionality.

    Unit tests passed.

    Made use of the new create_if_missing and file input types
    functionality in an in-progress change.

    Commits

    Files