About Clamping/Clipping Values within Range
Using the max(min()) pattern you can ensure that a value is within a provided range:
def save_image(image, quality):
# Valid JPEG quality range
quality = max(1, min(100, quality))
image.save(output, quality=quality)
Whichever quality value is provided to the function, the quality for the image will be no lower than 1 and no higher than 100.
Also by me
Django Messaging
For Django-based social platforms.
Django App for You
Django Paddle Subscriptions
For Django-based SaaS projects.
Django App for You
Django GDPR Cookie Consent
For Django websites that use cookies.
Django App for You