Git Product home page Git Product logo

django-thumb's Introduction

python version PyPI version PyPI - License coverage

Django-thumb

django-thumb is a simple Django app contains two models fields to generate images from videos and write on images.

  • Quick Preview for VideoThumbnailField(thumbnail)

testmodel

install

pip install django-thumb # try pip3 if it didn't work

Quick setup

  1. Add "thumb" to your INSTALLED_APPS setting like this::
    INSTALLED_APPS = [
        ...
        'thumb',
    ]

2. Add the STATIC_ROOT, MEDIA_ROOT and MEDIA_URL in setting like:
   STATIC_ROOT = os.path.join(BASE_DIR, "static")
   MEDIA_ROOT = 'media'
   MEDIA_URL = '/media/'

3. Add the MEDIA path to your urlpatterns in urls.py like:
	....
    from django.conf.urls.static import static
    from django.conf import settings

    urlpatterns = [
        ...
    ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

4. Run python manage.py collectstatic to create the static fields in your root.

5. now you can use the app model fields like:
from thumb import ImageThumbnailField, VideoThumbnailField

simple Model examples to test the fields

at first make sure that you made all the setup above
  • create the models:

in any app inside models.py file we will made these two models:

from django.db import models
from thumb import ImageThumbnailField, VideoThumbnailField

class Media(models.Model):
    video = models.FileField()
    # it's to be VideoThumbnailField(video_field_name="video") but "video" is the default
    thumbnail = VideoThumbnailField()


class MediaTwo(models.Model):
    thumbnail = ImageThumbnailField()
  • now run the migrations in your terminal:

python manage.py makemigrations
python manage.py migrate
  • add the models to your admin.py inside the same app to test it

from django.contrib import admin
from .models import Media, MediaTwo

admin.site.register(Media)
admin.site.register(MediaTwo)

now eveything is ready to test let's test make sure you got the same templates as the pictures below

  • in the Model media we can choose cascade like human appear to caputre at or enter the time MM:SS or just choose random

media_model

  • in the Model media two it's just one field thumbnail it's normal ImageField but you can add text to it

media_two_model


ADD more Cascade choices

  • you can add more cascade choices by adding yours in a folder in the your django project dir then add the xml cascade files their, after you've to add the choices in the settings.py :
CASCADE_DATA = (
    ('eyes', [os.path.join(BASE_DIR, "<your_cascades_folder>/haarcascade_eyes.xml")]),
    ('human with clear eyes', [os.path.join(BASE_DIR, "<your_cascades_folder>/haarcascade_frontalface.xml"),
                              os.path.join(BASE_DIR, "<your_cascades_folder>/haarcascade_eyes.xml")]),
)
  • note: you can add more than 1 cascade in the same choice but the each one has to be inside the later like the eyes inside the face ..etc, but don't do it except you really need to because it'll slow down the save process

change the cascade accurasy

  • by default each cascade has to be at least 0.3 of the hole width and height of the video frame, you can change it by add in the settings.py:
CASCADE_RATIO = {
		"width": <your_value_has_to_be_from_0_to_1>,
                 "height": <your_value_has_to_be_from_0_to_1>,
		 }
  • note: if you've a choice with multi cascade like human with smile each cascade has to have this ratio to the later

in this project I used:

  • opencv in image processing and text writing
  • jscolor in the color field

django-thumb's People

Contributors

amranwar avatar

Watchers

James Cloos avatar Mohamed Eid 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.