美文网首页程序员
使用easy_thumbnails轻松为图片创建缩略图

使用easy_thumbnails轻松为图片创建缩略图

作者: 画星星高手 | 来源:发表于2018-04-26 23:50 被阅读45次

    关于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

    官方推荐的第三方库

    关于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 docs directory.

    了解更多请打开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="" />
    

    更多使用方法请参考官方文档

    About

    了解更多有趣的操作请关注我的微信公众号:DealiAxy
    每一篇文章都在我的博客有收录:blog.deali.cn

    相关文章

      网友评论

        本文标题:使用easy_thumbnails轻松为图片创建缩略图

        本文链接:https://www.haomeiwen.com/subject/ypjvlftx.html