Coder Social home page Coder Social logo

andyshao / html5-camera Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zevero/html5-camera

0.0 3.0 0.0 15 KB

using an invisible HTML5 input tag to capture an image on ios and android. Image is resized, oriented and uploaded by XHR with progress

License: GNU General Public License v2.0

JavaScript 100.00%

html5-camera's Introduction

Camera

Using an invisible HTML5 input tag to capture a foto on ios and android. Foto is resized, oriented and uploaded by XHR with progress info

Usage example

####Browser

  var $info = $('#photo_info');
  var showInfo = function(s){// true ... ok, number ... percentage, string ... error
        $info.html((s.response)?s.response:(isNaN(s))?s:s + '%');
  };
  var showPhoto = function(canvas){$('#image').attr('src', canvas.toDataUrl());};

  $('#photo_button').click(function(){
    camera({
      photo_max_size:     800,       //resize to 800 pixel (height or width)
      photo_jpeg_quality: 0.7,       //jpeg-quality from 0 to 1.0
      xhr:                '/foto',   //url of where the photo shall be uploaded
      callback_xhr:       showInfo,  //show some info on upload progress
      callback_canvas:   showPhoto  //display the photo in an img-element
    });
  });

####Server

var formidable = require('formidable');
router.post('/foto', function(req, res) {
   var form = new formidable.IncomingForm();
   form.uploadDir = './data/location';
   form.keepExtensions = true;
   form.maxFieldsSize = 5 * 1024 * 1024;
   form.parse(req, function(err, fields, files) {
      //console.log('files:',files,'fields:',fields);
      var f = files.camera;
      if (!f) return res.send('Error ... no file!');
      //console.log('foto rename: ',f.path,f.name);
      require('fs').rename(f.path, form.uploadDir+'/'+f.name, function(err) {
        if (err) return res.send('foto rename error: ' + err);
        res.send('Got Photo');
      });
    });
  });

Dependencies

Tested

Chrome 44, Firefox 38, ios8, ios9, Android 5

Todos?

  • Seperation of Capture and Upload to handle offline situations
  • Usage of getUserMedia where possible

Alternatives

html5-camera's People

Contributors

zevero avatar

Watchers

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.