Update image upload handler to be content-type aware

Update handle_image: made filetype required and not optional
Updated handle_image usage to reflect changes
This commit is contained in:
Nathan Beals
2022-04-23 00:11:04 -04:00
parent 9adc1f7266
commit 8df3009cb2
3 changed files with 12 additions and 7 deletions

View File

@ -38,10 +38,12 @@ def get_filetype(name):
# TODO this whole file needs proper documentation, refactoring, and testing
# TODO also add env variable to define which images sizes should be compressed
def handle_image(request, image_object, filetype='.jpeg'):
# filetype argument can not be optional, otherwise this function will treat all images as if they were a jpeg
# Because it's no longer optional, no reason to return it
def handle_image(request, image_object, filetype):
if (image_object.size / 1000) > 500: # if larger than 500 kb compress
if filetype == '.jpeg' or filetype == '.jpg':
return rescale_image_jpeg(image_object), filetype
return rescale_image_jpeg(image_object)
if filetype == '.png':
return rescale_image_png(image_object), filetype
return image_object, filetype
return rescale_image_png(image_object)
return image_object