django应用程序,用于调整图像大小,并通过模板标记生成src和srcset值。
django-responsive-images的Python项目详细描述
用于调整图像大小和生成src和srcset值的django应用程序 通过模板标签。它的目的是非常容易使用;只要放下它 并使用模板标记。
需要django和枕头。
安装
通过PIP安装:
pip install django-responsive-images
然后将responsive_images添加到已安装的应用程序中。
用法
大部分情况下,这个应用程序是通过模板标签使用的。 当前支持的功能演示如下:
{% load responsive_images %} {# resize and crop an image attached to instance to fit 500x500 #} <img src="{% src instance.image_field 500x500 %}"> {# resize (without cropping) to fit 500x500 #} {# note: resulting size will likely not match both dimensions #} <img src="{% src instance.image_field 500x500 nocrop %}"> {# specify crop position as percent: X,Y #} <img src="{% src instance.image_field 500x500 50,20 %}"> {# center crop is the default, all of these are equivalent #} <img src="{% src instance.image_field 500x500 %}"> <img src="{% src instance.image_field 500x500 crop %}"> <img src="{% src instance.image_field 500x500 center %}"> <img src="{% src instance.image_field 500x500 50,50 %}"> {# resize image multiple times and create srcset #} <img srcset="{% srcset instance.field 400x400 800x800 1600x1600 %}"> {# srcset also allows nocrop and crop position #} <img srcset="{% srcset instance.field 400x400 800x800 nocrop %}"> <img srcset="{% srcset instance.field 400x400 800x800 50,20 %}">
注意:如果指定的大小大于一个或两个中的源图像 尺寸,结果图像将与指定的尺寸不匹配。图像 永远都不会升级。生成的图像只能在一个中调整大小 尺寸(如果裁剪)或它可能返回原始图像。在任何一个 在case中,srcset标记将输出所用图像的正确宽度。