From 2467dfe91202424f0dc0c9178fc3458c0aafa77e Mon Sep 17 00:00:00 2001 From: Matthew Tretter Date: Fri, 10 Feb 2012 20:46:16 -0500 Subject: [PATCH] Rename `resize.Crop` to `resize.Fill` --- README.rst | 4 ++-- imagekit/processors/resize.py | 31 +++++++++++++++++++------------ tests/core/tests.py | 4 ++-- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/README.rst b/README.rst index 5ca153f..8c7f99d 100644 --- a/README.rst +++ b/README.rst @@ -61,7 +61,7 @@ your spec, you can expose different versions of the original image:: class Photo(models.Model): original_image = models.ImageField(upload_to='photos') thumbnail = ImageSpecField([Adjust(contrast=1.2, sharpness=1.1), - resize.Crop(50, 50)], image_field='original_image', + resize.Fill(50, 50)], image_field='original_image', format='JPEG', options={'quality': 90}) The ``thumbnail`` property will now return a cropped image:: @@ -72,7 +72,7 @@ The ``thumbnail`` property will now return a cropped image:: photo.original_image.width # > 1000 The original image is not modified; ``thumbnail`` is a new file that is the -result of running the ``imagekit.processors.resize.Crop`` processor on the +result of running the ``imagekit.processors.resize.Fill`` processor on the original. The ``imagekit.processors`` module contains processors for many common diff --git a/imagekit/processors/resize.py b/imagekit/processors/resize.py index 79b5407..b9f7c5c 100644 --- a/imagekit/processors/resize.py +++ b/imagekit/processors/resize.py @@ -3,7 +3,7 @@ from .crop import SmartCrop as _SmartCrop import warnings -class Crop(object): +class Fill(object): """ Resizes an image , cropping it to the specified width and height. @@ -37,15 +37,15 @@ class Crop(object): :param anchor: Specifies which part of the image should be retained when cropping. Valid values are: - - Crop.TOP_LEFT - - Crop.TOP - - Crop.TOP_RIGHT - - Crop.LEFT - - Crop.CENTER - - Crop.RIGHT - - Crop.BOTTOM_LEFT - - Crop.BOTTOM - - Crop.BOTTOM_RIGHT + - Fill.TOP_LEFT + - Fill.TOP + - Fill.TOP_RIGHT + - Fill.LEFT + - Fill.CENTER + - Fill.RIGHT + - Fill.BOTTOM_LEFT + - Fill.BOTTOM + - Fill.BOTTOM_RIGHT """ self.width = width @@ -54,8 +54,8 @@ class Crop(object): def process(self, img): cur_width, cur_height = img.size - horizontal_anchor, vertical_anchor = Crop._ANCHOR_PTS[self.anchor or \ - Crop.CENTER] + horizontal_anchor, vertical_anchor = Fill._ANCHOR_PTS[self.anchor or \ + Fill.CENTER] ratio = max(float(self.width) / cur_width, float(self.height) / cur_height) resize_x, resize_y = ((cur_width * ratio), (cur_height * ratio)) crop_x, crop_y = (abs(self.width - resize_x), abs(self.height - resize_y)) @@ -75,6 +75,13 @@ class Crop(object): return img +class Crop(Fill): + def __init__(self, *args, **kwargs): + warnings.warn('`imagekit.processors.resize.Crop` has been renamed to' + '`imagekit.processors.resize.Fill`.', DeprecationWarning) + super(Crop, self).__init__(*args, **kwargs) + + class Fit(object): """ Resizes an image to fit within the specified dimensions. diff --git a/tests/core/tests.py b/tests/core/tests.py index 6443f02..6fe7eb2 100644 --- a/tests/core/tests.py +++ b/tests/core/tests.py @@ -11,7 +11,7 @@ from imagekit import utils from imagekit.lib import Image from imagekit.models import ImageSpecField from imagekit.processors import Adjust -from imagekit.processors.resize import Crop +from imagekit.processors.resize import Fill from imagekit.processors.crop import SmartCrop @@ -19,7 +19,7 @@ class Photo(models.Model): original_image = models.ImageField(upload_to='photos') thumbnail = ImageSpecField([Adjust(contrast=1.2, sharpness=1.1), - Crop(50, 50)], image_field='original_image', format='JPEG', + Fill(50, 50)], image_field='original_image', format='JPEG', options={'quality': 90}) smartcropped_thumbnail = ImageSpecField([Adjust(contrast=1.2,