Code Monkey home page Code Monkey logo

phonegap-plugin-image-capture's Introduction

phonegap-plugin-image-capture Build Status

This plugin provides an implementation for clicking pictures with a device camera based on the W3C MediaStream Image Capture API for iOS and Android. In order to achieve the image capture, this plugin uses the phonegap-plugin-media-stream which is based on the W3C Media Stream API. The phonegap-plugin-media-stream makes the mediastream track available to the phonegap-plugin-image-capture which allows the user to click a picture. The phonegap-plugin-media-stream is added as a dependency to the phonegap-plugin-image-capture plugin.

Installation

phonegap plugin add phonegap-plugin-image-capture

phonegap plugin add https://github.com/phonegap/phonegap-plugin-image-capture.git

ImageCapture Constructor

The ImageCapture constructor uses the mediastream track obtained by using the phonegap-plugin-media-stream to create an object.

Example

        navigator.mediaDevices.getUserMedia({
            'audio': true,
            'video': {
                facingMode: 'user'
            }
        }).then(function(getmedia) {

            var track = getmedia.getVideoTracks()[0];
            var imageCapture = new ImageCapture(track);
        });

The imageCapture object

The imageCapture object has the following methods:

imageCapture.takePhoto(optional PhotoSettings photoSettings)

The takePhoto() promise accepts an optional PhotoSettings parameter and allows the user to take a picture. The implementation in iOS allows the user to open a camera view and click a picture. Android has integrated support for the W3C Media Stream API and the W3C MediaStream Image Capture API from Chrome 59 and the latest Android System Webview. The takePhoto() promise resolves with a blob on successful capture of a picture.

Example

        imageCapture.takePhoto()
            .then(blob => {
                console.log('Photo taken: ' + blob.type + ', ' + blob.size + 'B');
                const image = document.querySelector('img'); // img is an <img> tag
                image.src = URL.createObjectURL(blob);
            })
            .catch(err => console.error('takePhoto() failed: ', err));

imageCapture.getPhotoCapabilities()

The getPhotoCapabilities() method retrieves the ranges of available configuration options, if any. The promise returns the value of the following four properties if available:

  • redEyeReduction : Value can be one of never , always and controllable if available.
  • imageHeight : Has max, min and step values if available.
  • imageWidth : Has max, min and step values if available.
  • fillLightMode : Value can be one of auto, flash and off if available.

Example

        imageCapture.getPhotoCapabilities()
            .then(function(capabilities){
                console.log(capabilities);
            });

imageCapture.getPhotoSettings()

This method returns the current configuration values for the settings for taking a picture. The following values are returned by this promise :

  • redEyeReduction (Boolean) ,if available.
  • imageHeight (Number)
  • imageWidth (Number)
  • fillLightMode : One of the three values : auto, flash and off ,if available.

Example

        imageCapture.getPhotoSettings()
            .then(function(settings){
                console.log(settings);
            });

imageCapture.grabFrame()

This method takes a snapshot of the live video being held in the mediastream track, returning an ImageBitmap if successful. This method is not supported on iOS and rejected promise with DOMException is returned.

Quirks

In order to add a blob object as a source for an img tag, blob: should be added to the img-src part of the Content-Security-Policy meta tag in your index.html .

phonegap-plugin-image-capture's People

Contributors

stevengill avatar maverickmishra avatar macdonst avatar infil00p avatar agrieve avatar purplecabbage avatar alsorokin avatar shazron avatar ldeluca avatar jcesarmobile avatar muratsu avatar vladimir-kotikov avatar hermwong avatar riknoll avatar filmaj avatar jamesjong avatar cmarcelk avatar dblotsky avatar clelland avatar swbradshaw avatar zalun avatar nikhilkh avatar csantanapr avatar bennmapes avatar hardeep avatar kicken avatar stacic avatar surajpindoria avatar sgrebnov avatar m-revetria avatar

Watchers

James Cloos 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.