Skip to content

Simple Django app to provide a WebcamPictureField, derived from ImageField

License

Notifications You must be signed in to change notification settings

rnetonet/django-webcampicture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

django-webcampicture

django-webcampicture is a very simple Django app that provides a specialization of Django's native ImageField: WebcamPictureField, which allows users to save images taken from their webcams, instead of uploading.

Quick start

  1. Install using pip:
pip install django-webcampicture
  1. Add "webcampicture" to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [
    ...
    'webcampicture',
]
  1. Use the field in your models:
from django.db import models
from webcampicture.fields import WebcamPictureField


class Child(models.Model):
    name = models.CharField("Name", max_length=255)

    # WebcamPictureField takes the same parameters as ImageField,
    # besides the "width" and "height" positional parameters.
    picture = WebcamPictureField(
        "Picture", width=480, height=360, upload_to="pictures", blank=True
    )

    # Image URL example...
    @property
    def picture_url(self):
        if self.picture and hasattr(self.picture, "url"):
            return self.picture.url
  1. Remember to include in your templates:
{% load static %}
<link rel="stylesheet" href="{% static "webcampicture/css/webcampicture.css" %}">
<script src="{% static 'webcampicture/js/webcampicture.js' %}"></script>

Demo

demo

Settings and default values

WEBCAM_BASE64_PREFIX = "data:image/png;base64,"
WEBCAM_CONTENT_TYPE = "image/png"
WEBCAM_FILENAME_SUFFIX = ".png"

Overridable templates

webcampicture/webcampicture.html

About

Simple Django app to provide a WebcamPictureField, derived from ImageField

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published