Skip to content

Commit 323659d

Browse files
author
Agus Makmun
committed
feat: bump version, fix save with commit arg, implement black
1 parent d71ca1b commit 323659d

File tree

7 files changed

+11
-11
lines changed

7 files changed

+11
-11
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ dist/
77
*backup*
88
db.sqlite3
99
.vscode
10+
image_optimizer_demo/media/*

README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ file. Note: it is a good idea to keep this secret
9595
in this case (400, 300) pixels.
9696
"""
9797
image = OptimizedImageField(
98-
upload_to='uploads/collaborators/%Y/%m/%d',
98+
upload_to="uploads/%Y/%m/%d",
9999
optimized_image_output_size=(400, 300),
100-
optimized_image_resize_method='cover' # 'thumbnail', 'cover' or None
100+
optimized_image_resize_method="cover" # "crop", "cover", "contain", "width", "height", "thumbnail" or None
101101
)
102102

103103

image_optimizer/utils.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ def get_file_name(image_data):
1818

1919
def get_file_extension(file_name):
2020
extension = None
21-
2221
# Get image file extension
2322
if file_name.split(".")[-1].lower() != "jpg":
2423
extension = file_name.split(".")[-1].upper()
2524
else:
2625
extension = "JPEG"
27-
2826
return extension
2927

3028

@@ -37,7 +35,9 @@ def image_optimizer(image_data, output_size=None, resize_method=None):
3735
Optimize an image that has not been saved to a file.
3836
:param `image_data` is image data, e.g from request.FILES['image']
3937
: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"
4141
:return optimized image data.
4242
"""
4343
if OPTIMIZED_IMAGE_METHOD == "pillow":
@@ -49,10 +49,11 @@ def image_optimizer(image_data, output_size=None, resize_method=None):
4949
# If output_size is set, resize the image with the selected
5050
# resize_method. 'thumbnail' is used by default
5151
if output_size is not None:
52-
5352
if resize_method:
5453
image = resizeimage.resize(
55-
method=resize_method, image=image, size=output_size,
54+
method=resize_method,
55+
image=image,
56+
size=output_size,
5657
)
5758

5859
output_image = Image.new(
@@ -64,9 +65,7 @@ def image_optimizer(image_data, output_size=None, resize_method=None):
6465
int((output_size[0] - image.size[0]) / 2),
6566
int((output_size[1] - image.size[1]) / 2),
6667
)
67-
6868
output_image.paste(image, output_image_center)
69-
7069
else:
7170
# If output_size is None the output_image
7271
# would be the same as source

image_optimizer_demo/app_demo/forms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def save(self, commit=True):
2828
raise forms.ValidationError(error)
2929

3030
instance.image = image
31-
instance.save(commit=True)
31+
instance.save()
3232
return instance
3333

3434
return super().save(commit)
Binary file not shown.
Binary file not shown.

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from setuptools import setup, find_packages
44

5-
__VERSION__ = "1.0.2"
5+
__VERSION__ = "1.0.3"
66
__AUTHOR__ = "Agus Makmun (Summon Agus)"
77
__AUTHOR_EMAIL__ = "[email protected]"
88

0 commit comments

Comments
 (0)