使用easy_thumbnails轻松为图片创建缩略图
关于Django的缩略图 我在Django的官方文档里看了一下,没有找到有关缩略图的官方库,不过在Django的Wiki里头倒是看到了一篇关于使用缩略图的介绍,请参考:https://code.djangoproject.com/wiki/ThumbNails 关于Problem的描述 The majority of applications that have images, probably
目录5 个章节
关于Django的缩略图
我在Django的官方文档里看了一下,没有找到有关缩略图的官方库,不过在Django的Wiki里头倒是看到了一篇关于使用缩略图的介绍,请参考:https://code.djangoproject.com/wiki/ThumbNails
关于Problem的描述
The majority of applications that have images, probably use thumbnails in some capacity. There is no standard thumbnail capability in Django but there are a couple of different options out there that people have created. This page is an attempt to gather them in one place and discuss the best strategy for integrating one in Django.
Current Implementations
官方推荐的第三方库
- sorl-thumbnail is excellent.
- SmileyChris's easy-thumbnails is also excellent.
- aino-convert a versatile solution for the fastidious.
- Nesh's Thumbnail
- image-kit a django-ish way of resizing images, with image models
- Here's a more simple filter from Django snippets - Simple filter
- In Ticket #4115 you will find a patch with a contrib.thumbnails package - good documented; read the Google Discussion mentioned above for some thoughts about the implementation.
- Quick tip for adding thumbnails - Blog posting
- Yet another approach to adding a thumbnail - CustomUploadAndFilters
- Snippet that creates thumbnails on-demand using dynamics methods - Snippet 619
- Yet another method to resize image on upload - Automatically resizing uploaded images
- Custom field for image resizing on upload - http://djangothumbnails.com/
- Template tag for resizing to exact dimensions: http://bitbucket.org/winsmith/django-thumbnail/wiki/Home
- Easy frontend filter for resizing on the fly (great for mobile and mediaqueries) django-imagefit
关于easy_thumbnails
A powerful, yet easy to implement thumbnailing application for Django 1.8+ Below is a quick summary of usage. For more comprehensive information, view the full documentation online or the peruse the project's
docsdirectory.
了解更多请打开easy_thumbnails的项目主页,链接在上面有,公众号推文不能点击链接请访问原文。
使用步骤简介
安装
pip install easy-thumbnails
配置
编辑settings.py
INSTALLED_APPS = (
...
'easy_thumbnails',
)
THUMBNAIL_ALIASES = {
'': {
'avatar': {'size': (50, 50), 'crop': True},
},
}
Run manage.py migrate easy_thumbnails.
在templates中使用
{% load thumbnail %}
<img src="{{ profile.photo|thumbnail_url:'avatar' }}" alt="" />
更多使用方法请参考官方文档
_EOF_
使用easy_thumbnails轻松为图片创建缩略图
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
使用Django-Channels实现websocket通信+大模型对话
这个只是简单的demo,实际上生产还得考虑很多问题,本文就是为 channels 的应用开了个头,后续有新的研究成果会持续更新博客~
2024-08-14 · Django · 约 1 分钟
Django项目笔记:sessions处理以及复杂对象序列化
前言:一点题外话 我发现,不更新博客的时候,不是非常忙,就是效率非常低。最近没怎么更新博客,原因是第二种= =。惭愧惭愧。 今天效率出奇的高,一天时间把PassNote后端的接口全部写完了,Django很好用,不过实际项目中还是有些框架不能实现的功能需要解决的,我比较喜欢造轮子,不过为了保证效率,还是尽量用现成的工具,减少不必要的折腾。 关于PassNote 之前应该在博客有说过,这是一个密码管理
2022-04-02 · Django · 约 1 分钟
给Django-Admin添加验证码和多次登录尝试限制
Django自带的Admin很好用,但是放到生产环境总还差了点什么= = 看看admin的介绍: Django奉行Python的内置电池哲学。它自带了一系列在Web开发中用于解决常见问题或需求的额外的、可选工具。这些工具和插件,例如django.contrib.redirects都必须在settings中的INSTALLED_APPS处进行注册,有的还需要执行manage.py migrate命令
2021-12-18 · Django · 约 1 分钟
Django的信号机制入门
概念 django自带一套信号机制来帮助我们在框架的不同位置之间传递信息。也就是说,当某一事件发生时,信号系统可以允许一个或多个发送者(senders)将通知或信号(signals)发送给一组接受者(receivers)。 (感觉就很像Qt的信号与槽机制) 信号系统包含以下三要素: 发送者-信号的发出方 信号-信号本身 接收者-信号的接受者 Django内置了一整套信号,下面是一些比较常用的: 在
2022-08-26 · Django · 约 1 分钟
讨论
共 0 条加载评论中…