diff --git a/.gitignore b/.gitignore index 4017fe7..46dbf98 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ dist/ *backup* db.sqlite3 .vscode +image_optimizer_demo/media/* diff --git a/README.rst b/README.rst index 9625265..b807d6f 100644 --- a/README.rst +++ b/README.rst @@ -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 ) diff --git a/image_optimizer/utils.py b/image_optimizer/utils.py index 572581b..e07f958 100644 --- a/image_optimizer/utils.py +++ b/image_optimizer/utils.py @@ -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 @@ -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": @@ -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( @@ -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 diff --git a/image_optimizer_demo/app_demo/forms.py b/image_optimizer_demo/app_demo/forms.py index d888f17..6f81d90 100644 --- a/image_optimizer_demo/app_demo/forms.py +++ b/image_optimizer_demo/app_demo/forms.py @@ -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) diff --git a/image_optimizer_demo/media/uploads/2022/08/10/image_1.png b/image_optimizer_demo/media/uploads/2022/08/10/image_1.png deleted file mode 100644 index 4a9fbfb..0000000 Binary files a/image_optimizer_demo/media/uploads/2022/08/10/image_1.png and /dev/null differ diff --git a/image_optimizer_demo/media/uploads/2022/08/10/image_1_xBxnqGC.png b/image_optimizer_demo/media/uploads/2022/08/10/image_1_xBxnqGC.png deleted file mode 100644 index 1614269..0000000 Binary files a/image_optimizer_demo/media/uploads/2022/08/10/image_1_xBxnqGC.png and /dev/null differ diff --git a/setup.py b/setup.py index aef589c..7cdf819 100644 --- a/setup.py +++ b/setup.py @@ -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__ = "summon.agus@gmail.com"