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标记将输出所用图像的正确宽度。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何使用MVC设计模式观察嵌套对象   java将多个客户端连接到服务器   合并Java Web应用程序   Spring Security中未捕获java AuthenticationSuccessEvent   java Firebase JSON到Arraylist内部的Arraylist,存在对象问题   在Java15的sealedclasses特性中,final类和非密封类之间有什么区别?   java我可以使用数组。copyOf制作二维数组的防御副本?   java球不会在屏幕上移动   Java类如何在同一个文件中包含两个类?   java使用“Character.isWhiteSpace”删除所有空白   java阻止在RealmList中保存时创建领域对象   如何仅在ConnectionFactory上使用Java JMS身份验证   spring可以强制java对象在运行时实现接口吗?   socket无法在JAVA中使用TCP启用双工模式通信