Skip to content

_calculate_scaling_factor doesn't work right when crop == 'noop' #800

@zackw

Description

@zackw

As requested, I am re-filing bug #407, which was closed despite the buggy code not having changed at all.

def _calculate_scaling_factor(self, x_image, y_image, geometry, options):
crop = options['crop']
factors = (geometry[0] / x_image, geometry[1] / y_image)
return max(factors) if crop else min(factors)

The image will be scaled to max(factors) when crop is noop, which is incorrect. crop being set to noop is documented to scale the image the same as if crop had been unset (https://sorl-thumbnail.readthedocs.io/en/latest/template.html#crop)

Suggested change:

def _calculate_scaling_factor(self, x_image, y_image, geometry, options):
    crop = options['crop']
    factors = (geometry[0] / x_image, geometry[1] / y_image)
    if not crop or crop == 'noop':
        return min(factors)
    else:
        return max(factors)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions