Skip to content

Commit

Permalink
feat: bump version, fix save with commit arg, implement black
Browse files Browse the repository at this point in the history
  • Loading branch information
Agus Makmun committed Oct 18, 2022
1 parent d71ca1b commit 323659d
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ dist/
*backup*
db.sqlite3
.vscode
image_optimizer_demo/media/*
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ file. Note: it is a good idea to keep this secret
in this case (400, 300) pixels.
"""
image = OptimizedImageField(
upload_to='uploads/collaborators/%Y/%m/%d',
upload_to="uploads/%Y/%m/%d",
optimized_image_output_size=(400, 300),
optimized_image_resize_method='cover' # 'thumbnail', 'cover' or None
optimized_image_resize_method="cover" # "crop", "cover", "contain", "width", "height", "thumbnail" or None
)


Expand Down
13 changes: 6 additions & 7 deletions image_optimizer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ def get_file_name(image_data):

def get_file_extension(file_name):
extension = None

# Get image file extension
if file_name.split(".")[-1].lower() != "jpg":
extension = file_name.split(".")[-1].upper()
else:
extension = "JPEG"

return extension


Expand All @@ -37,7 +35,9 @@ 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 or resizeimage.resize() method argument values. # noqa: E501
:param `resize_method` is string resize method, choices are:
None or resizeimage.resize() method argument values,
i.e: "crop", "cover", "contain", "width", "height", "thumbnail"
:return optimized image data.
"""
if OPTIMIZED_IMAGE_METHOD == "pillow":
Expand All @@ -49,10 +49,11 @@ def image_optimizer(image_data, output_size=None, resize_method=None):
# If output_size is set, resize the image with the selected
# resize_method. 'thumbnail' is used by default
if output_size is not None:

if resize_method:
image = resizeimage.resize(
method=resize_method, image=image, size=output_size,
method=resize_method,
image=image,
size=output_size,
)

output_image = Image.new(
Expand All @@ -64,9 +65,7 @@ def image_optimizer(image_data, output_size=None, resize_method=None):
int((output_size[0] - image.size[0]) / 2),
int((output_size[1] - image.size[1]) / 2),
)

output_image.paste(image, output_image_center)

else:
# If output_size is None the output_image
# would be the same as source
Expand Down
2 changes: 1 addition & 1 deletion image_optimizer_demo/app_demo/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def save(self, commit=True):
raise forms.ValidationError(error)

instance.image = image
instance.save(commit=True)
instance.save()
return instance

return super().save(commit)
Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import setup, find_packages

__VERSION__ = "1.0.2"
__VERSION__ = "1.0.3"
__AUTHOR__ = "Agus Makmun (Summon Agus)"
__AUTHOR_EMAIL__ = "[email protected]"

Expand Down

0 comments on commit 323659d

Please sign in to comment.