Skip to content

Commit d71ca1b

Browse files
authored
Merge pull request #10 from Vayel/resize_methods
Make it possible to use all resize methods
2 parents b4e591b + 9d52d9b commit d71ca1b

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

image_optimizer/utils.py

+4-14
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def image_optimizer(image_data, output_size=None, resize_method=None):
3737
Optimize an image that has not been saved to a file.
3838
:param `image_data` is image data, e.g from request.FILES['image']
3939
:param `output_size` is float pixel scale of image (width, height) or None, for example: (400, 300) # noqa: E501
40-
:param `resize_method` is string resize method, choices are: None, "thumbnail", or "cover". # noqa: E501
40+
:param `resize_method` is string resize method, choices are: None or resizeimage.resize() method argument values. # noqa: E501
4141
:return optimized image data.
4242
"""
4343
if OPTIMIZED_IMAGE_METHOD == "pillow":
@@ -50,20 +50,10 @@ def image_optimizer(image_data, output_size=None, resize_method=None):
5050
# resize_method. 'thumbnail' is used by default
5151
if output_size is not None:
5252

53-
if resize_method not in ("thumbnail", "cover", None):
54-
message = (
55-
"optimized_image_resize_method misconfigured, "
56-
"it's value must be 'thumbnail', 'cover' or None"
53+
if resize_method:
54+
image = resizeimage.resize(
55+
method=resize_method, image=image, size=output_size,
5756
)
58-
raise Exception(message)
59-
60-
elif resize_method == "thumbnail":
61-
image = resizeimage.resize_thumbnail(
62-
image, output_size, resample=Image.LANCZOS
63-
)
64-
65-
elif resize_method == "cover":
66-
image = resizeimage.resize_cover(image, output_size, validate=False)
6757

6858
output_image = Image.new(
6959
"RGBA",

0 commit comments

Comments
 (0)