【问题标题】:Django-Filebrowser cannot create a version with auto width and constrained height?Django-Filebrowser 无法创建具有自动宽度和约束高度的版本?
【发布时间】:2014-12-12 22:03:50
【问题描述】:

我一直在使用 Django-Filebrowser 并设置我的版本 as specified in the 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': ''},

这里有没有我遗漏的技巧,或者图书馆没有这个能力?

【问题讨论】:

    标签: django django-filebrowser


    【解决方案1】:

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

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

    示例版本定义:

    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):
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-25
      • 2018-04-17
      • 1970-01-01
      相关资源
      最近更新 更多