1

我一直在使用 Django-Filebrowser 并按照 docs 中指定的方式设置我的版本,这表明您指定的图像版本如下:

VERSIONS = getattr(settings, "FILEBROWSER_VERSIONS", {
    'thumbnail': {'verbose_name': 'Thumbnail (1 col)', 'width': 60, 'height': 60, 'opts': 'crop'},
    'small': {'verbose_name': 'Small (2 col)', 'width': 140, 'height': '', 'opts': ''},
})

...请注意具有未指定高度的“小”版本大小,它成功生成了具有约束宽度和自动高度的图像版本。这对我来说很成功,但是反过来却没有(限制高度但自动宽度):

'auto_width': {'verbose_name': 'Auto Width', 'width': '', 'height': 140, 'opts': ''},

这里有我遗漏的技巧,还是图书馆没有这种能力?

4

1 回答 1

0

我刚刚遇到了同样的问题并解决了它:https ://github.com/sehmaschine/django-filebrowser/issues/278

在尝试生成具有固定高度和自动宽度的版本时,该scale_and_crop函数存在一个错误utils.py(相反它的工作方式就像一个魅力)。将创建版本图像,但具有原始大小。

示例版本定义:

FILEBROWSER_VERSIONS = { 
  'medium': {'verbose_name': 'Medium (4col )', 'width': '', 'height': 250, 'opts': ''},
}

原因是宽度变量是一个空字符串,它与浮点数进行比较,因此 if 语句返回 False 并且图像不会调整大小。

解决它的一种方法是将宽度字符串转换为浮点数以进行比较utils.py

66c65
<     if 'upscale' not in opts and x < width:
---
>     if 'upscale' not in opts and x < float(width or 0):
于 2015-07-24T18:45:48.327 回答