mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-04-05 14:20:58 +00:00
Rename resize.Crop to resize.Fill
This commit is contained in:
parent
c3ef5172c3
commit
2467dfe912
3 changed files with 23 additions and 16 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue