Skip to content

Commit

Permalink
Merge pull request #10 from Vayel/resize_methods
Browse files Browse the repository at this point in the history
Make it possible to use all resize methods
  • Loading branch information
agusmakmun authored Oct 18, 2022
2 parents b4e591b + 9d52d9b commit d71ca1b
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions image_optimizer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def image_optimizer(image_data, output_size=None, resize_method=None):
Optimize an image that has not been saved to a file.
:param `image_data` is image data, e.g from request.FILES['image']
:param `output_size` is float pixel scale of image (width, height) or None, for example: (400, 300) # noqa: E501
:param `resize_method` is string resize method, choices are: None, "thumbnail", or "cover". # noqa: E501
:param `resize_method` is string resize method, choices are: None or resizeimage.resize() method argument values. # noqa: E501
:return optimized image data.
"""
if OPTIMIZED_IMAGE_METHOD == "pillow":
Expand All @@ -50,20 +50,10 @@ def image_optimizer(image_data, output_size=None, resize_method=None):
# resize_method. 'thumbnail' is used by default
if output_size is not None:

if resize_method not in ("thumbnail", "cover", None):
message = (
"optimized_image_resize_method misconfigured, "
"it's value must be 'thumbnail', 'cover' or None"
if resize_method:
image = resizeimage.resize(
method=resize_method, image=image, size=output_size,
)
raise Exception(message)

elif resize_method == "thumbnail":
image = resizeimage.resize_thumbnail(
image, output_size, resample=Image.LANCZOS
)

elif resize_method == "cover":
image = resizeimage.resize_cover(image, output_size, validate=False)

output_image = Image.new(
"RGBA",
Expand Down

0 comments on commit d71ca1b

Please sign in to comment.