Giter VIP home page Giter VIP logo

cropimg-django's Introduction

django cropimg

Django app for generating thumbnails based on easythumbnails and cropimg js library.

https://raw.githubusercontent.com/rewardz/cropimg-django/master/screenshots/admin.png

Main features

  1. live update
    You define your thumbnails as soon as you select the image you want to upload without having to upload it first.
  2. cropping flexibility
    If you have a rectangle image that you want to fit in a square thumbnail, you can totally do that and remaining part of the square will be made transparent.
  3. extra helper buttons
    That would allow you to center image, align, fit width or fit height

Credits

Most of the ideas and code structure - but not actual code - of this project are based on Django Image Cropping.

A fork of cropimg was used as the Javascript library for selecting thumbnails.

Installation

  1. Add to requirements.txt:
git+https://github.com/rewardz/cropimg-django.git@master#egg=cropimg-django
  1. Include cropimg thumbnail processor in easythumbnails settings (settings.py)
from easy_thumbnails.conf import Settings as ThumbnailSettings
THUMBNAIL_PROCESSORS = (
    'cropimg.thumbnail_processors.crop_box',
) + ThumbnailSettings.THUMBNAIL_PROCESSORS
  1. Include cropimg to your installed apps (settings.py)
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    ...
    'cropimg',
]
  1. Add thumbnail fields to your model
from easy_thumbnails.files import get_thumbnailer
from cropimg.fields import CIImageField, CIThumbnailField

class MyModel(models.Model):
    my_img = CIImageField(upload_to="images/", blank=True, null=True)
    img_display = CIThumbnailField('my_img', (600, 400), blank=True, null=True)
    img_thumbnail = CIThumbnailField('my_img', (200, 200), blank=True, null=True)

    def get_thumbnail(self, size, value, default_url=""):
        if not self.my_img:
            return default_url
        return get_thumbnailer(self.img).get_thumbnail({
            'size': size,
            'ci_box': value,
        }).url

    def get_display_img_url():
        return self.get_thumbnail((600, 400), self.img_display)

    def get_thumbnail_img_url():
        return self.get_thumbnail((200, 200), self.img_thumbnail)

CIImageField accept same paramters as ImageField and can replace it without any code change. CIThumbnailField require field_name which you are generating thumbnail for & desired thumbnail size.

  1. in admin.py add
from cropimg.admin import CIAdminMixin

class MyModelAdmin(CIAdminMixin, admin.ModelAdmin):

This Mixin will ensure thumbnail fields are rendered properly in admin.

Using with Django tempales

Note: This library require jQuery and it assumes the library is already loaded.

  1. make sure you've included jQuery in yoru template
  2. include your form dependencies {form.media}
  3. just render your form as usual {{form.as_p}}

cropimg-django's People

Contributors

ramast avatar axolotedeaccion avatar sudhanshut1981 avatar

Stargazers

Arindam D avatar Shashi avatar Ben Boyd avatar Fanani M. Ihsan avatar Alican Toprak avatar Shige Abe avatar Jim Wombles avatar

Watchers

 avatar James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.