私の知る限り、sorl-thumbnail では、1 つのステップでそれを行うことはできません。最大高さのみが必要な場合は、「x100」ジオメトリ構文を使用できますが、固定幅は保証されません。
3 つの選択肢があります。
is_portrait フィルターを使用して、トリミングが必要かどうかを確認します。
{% if my_img|is_portrait %}
{% thumbnail my_img.filename "100x100" crop="top" as thumb %}
<img src="{{thumb}}" height="{{thumb.height}}" width="{{thumb.width}}"/>
{% endthumbnail %}
{% else %}
{% thumbnail my_img.filename "100" as thumb %}
<img src="{{thumb}}" height="{{thumb.height}}" width="{{thumb.width}}"/>
{% endthumbnail %}
{% endif %}
max_height でトリミングするカスタム sorl エンジンを作成します。
from sorl.thumbnail.engines.pil_engine import Engine
class MyCustomEngine(Engine):
def create(self, image, geometry, options):
image = super(MyCustomEngine, self).create(image, grometry, options)
if 'max_height' in options:
max_height = options['max_height']
# Do your thing here, crop, measure, etc
return image
{% thumbnail my_image.filename "100" max_height=100 as thumb %}
HTML 経由で画像のトリミングをシミュレートする
{% thumbnail my_img.filename "100" crop="top" as thumb %}
<figure><img src="{{thumb}}" height="{{thumb.height}}" width="{{thumb.width}}"/></figure>
{% endthumbnail %}
# Your CSS file
figure {
max-height: 100px;
overflow: hidden;
}