@@ -18,13 +18,11 @@ def get_file_name(image_data):
18
18
19
19
def get_file_extension (file_name ):
20
20
extension = None
21
-
22
21
# Get image file extension
23
22
if file_name .split ("." )[- 1 ].lower () != "jpg" :
24
23
extension = file_name .split ("." )[- 1 ].upper ()
25
24
else :
26
25
extension = "JPEG"
27
-
28
26
return extension
29
27
30
28
@@ -37,7 +35,9 @@ def image_optimizer(image_data, output_size=None, resize_method=None):
37
35
Optimize an image that has not been saved to a file.
38
36
:param `image_data` is image data, e.g from request.FILES['image']
39
37
: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 or resizeimage.resize() method argument values. # noqa: E501
38
+ :param `resize_method` is string resize method, choices are:
39
+ None or resizeimage.resize() method argument values,
40
+ i.e: "crop", "cover", "contain", "width", "height", "thumbnail"
41
41
:return optimized image data.
42
42
"""
43
43
if OPTIMIZED_IMAGE_METHOD == "pillow" :
@@ -49,10 +49,11 @@ def image_optimizer(image_data, output_size=None, resize_method=None):
49
49
# If output_size is set, resize the image with the selected
50
50
# resize_method. 'thumbnail' is used by default
51
51
if output_size is not None :
52
-
53
52
if resize_method :
54
53
image = resizeimage .resize (
55
- method = resize_method , image = image , size = output_size ,
54
+ method = resize_method ,
55
+ image = image ,
56
+ size = output_size ,
56
57
)
57
58
58
59
output_image = Image .new (
@@ -64,9 +65,7 @@ def image_optimizer(image_data, output_size=None, resize_method=None):
64
65
int ((output_size [0 ] - image .size [0 ]) / 2 ),
65
66
int ((output_size [1 ] - image .size [1 ]) / 2 ),
66
67
)
67
-
68
68
output_image .paste (image , output_image_center )
69
-
70
69
else :
71
70
# If output_size is None the output_image
72
71
# would be the same as source
0 commit comments