0

我在此模型中使用简单缩略图图像裁剪应用程序和别名(简化):

from image_cropping import ImageRatioField
from easy_thumbnails.fields import ThumbnailerImageField

class Image(SlugMixin, models.Model):
    slug_from_field = 'title'
    slug_length = 110

    image = ThumbnailerImageField('path', upload_to=get_file_name,
                                  resize_source=dict(
                                      size=(1600, 0), quality=95),
                                  width_field='width', height_field='height',
                                  blank=True, null=True)
    crop_thumb = ImageRatioField(
      'image', '120x90',
      help_text='Drag the handles and crop area to crop the image.',
      verbose_name="crop thumbnail")
    crop_image = ImageRatioField(
      'image', '400x300',
      free_crop=True,
      help_text='Drag the handles and crop area to crop the image.')
    ....

settings.py 中的别名定义:

THUMBNAIL_ALIASES = {
    '': {
        'small': {
            'size': (120, 90), 'detail': True, 'crop': True, 'upscale': True,
            'ALIAS': 'small', 'ratio_field': 'crop_thumb',
        },
        'medium': {
            'size': (240, 180), 'detail': True, 'crop': True, 'upscale': True,
            'ALIAS': 'medium', 'ratio_field': 'crop_thumb',
        },
        'large': {
            'size': (0, 400), 'quality': 90, 'detail': True, 'upscale': True,
            'ALIAS': 'large', 'ratio_field': 'crop_image',
        },
    },
}

THUMBNAIL_NAMER = 'easy_thumbnails.namers.alias'

我预计每张上传的图像会得到 3 个缩略图,但我得到了 4 个。预期的 3 个被命名为 my_image.jpg.small.jpg + medium 和 large,另外一个是 my_image.jpg..jpg 并且是 300px 宽。
就像它为空别名生成一个额外的缩略图,但我在我的代码中找不到任何可以做到这一点的东西。
任何想法?

4

1 回答 1

0

好的,我想我找到了答案。图片裁剪应用需要创建缩略图,以允许用户在后台调整裁剪区域并动态创建;它仅在用户与管理员交互时生成,这就是我的情况。

于 2021-02-11T18:13:42.917 回答