Easily Create Image Thumbnails with easy_thumbnails
About Django Thumbnails I took a look at Django's official documentation and didn't find an official library for thumbnails. However, I did find an introduction to using thumbnails in the Django Wiki. Please refer to: https://code.djangoproject.com/wiki/ThumbNails Description of the Problem The majority of applications that have images, probably
目录5 个章节
About Django Thumbnails
I took a look at Django's official documentation and didn't find an official library for thumbnails. However, I did find an introduction to using thumbnails in the Django Wiki. Please refer to: https://code.djangoproject.com/wiki/ThumbNails
Description of the 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
Officially recommended third-party libraries
- 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
About 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.
To learn more, please open the easy_thumbnails project homepage. The link is above. If you cannot click links in WeChat official account posts, please visit the original article.
Brief Overview of Usage Steps
Installation
pip install easy-thumbnails
Configuration
Edit settings.py
INSTALLED_APPS = (
...
'easy_thumbnails',
)
THUMBNAIL_ALIASES = {
'': {
'avatar': {'size': (50, 50), 'crop': True},
},
}
Run manage.py migrate easy_thumbnails.
Usage in templates
{% load thumbnail %}
<img src="{{ profile.photo|thumbnail_url:'avatar' }}" alt="" />
For more usage methods, please refer to the official documentation
_EOF_
Easily Create Image Thumbnails with easy_thumbnails
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
如何优雅地在Django项目里生成不重复的ID?
在生成唯一 ID 这件事上,Django 和其他后端框架没啥不同的,思路都是类似的,只不过可以借助 Python 生态偷懒一下…
2024-12-08 · Django · 约 1 分钟
Django快速开发实践:Drf框架和xadmin配置指北
步骤 既然是快速开发,那废话不多说,直接说步骤: 安装Djagno 安装Django Rest Framework 定义models 定义Rest framework的serializers 定义Rest framework的viewsets 配置Rest framework的router 配置管理后台admin 根据需要写template和对应的view 经过这些步骤就能得到一个具备完整的后端接
2022-09-06 · Django · 约 1 分钟
Django应用部署:uwsgi+Nginx方式
环境准备 nginx+uwsgi方式部署顾名思义,需要nginx和uwsgi两个软件包。 nginx不用说,是必备的,关于nginx的安装本文不再赘述,详情可以自行搜索或者参考我以前的文章: Debian8搭建LEMP环境 安装uwsgi pip install uwsgi 上传项目代码 & 测试 # 进入项目目录,具体目录请自行选择 cd /path/to/project # 建立虚拟环境 v
2022-04-02 · Django · 约 1 分钟
使用Django-Channels实现websocket通信+大模型对话
这个只是简单的demo,实际上生产还得考虑很多问题,本文就是为 channels 的应用开了个头,后续有新的研究成果会持续更新博客~
2024-08-14 · Django · 约 1 分钟
讨论
共 0 条加载评论中…