Coder Social home page Coder Social logo

titipakorn / react-camera Goto Github PK

View Code? Open in Web Editor NEW

This project forked from arjanj/react-camera

0.0 0.0 0.0 1.23 MB

A flexible camera component for React DOM. Take photos using the latest WebRTC API's.

Home Page: https://react-camera.netlify.com

License: MIT License

HTML 8.25% JavaScript 91.75%

react-camera's Introduction

React Camera

A flexible camera component for React DOM; take photos using the latest WebRTC API's.

Demo

See Demo ๐Ÿ“ธ

Installation

React Camera is designed to be installed through NPM and imported as an ES6 module.

npm install react-dom-camera

Then import it into your project.

import Camera from 'react-dom-camera';

Usage

Here is a basic example of how to use React Camera in a React app. This will render the Camera component "out of the box".

import React from 'react';
import Camera from 'react-dom-camera';

const App = () => <Camera />;

Taking a photo ๐Ÿ“ธ

React Camera is setup to take an image of the current frame when the capture button is clicked, however, to access the image you must use the onTakePhoto prop which passes you the image. The image can be set as the src value on an <img> element for example.

import React from 'react';
import Camera from 'react-dom-camera';

const App = () => (
  <Camera
    onTakePhoto={image =>
      console.log(image, 'do whatever you want with the image')
    }
  />
);

Custom capture button

If you're not a fan of the default capture button you can easily use your own component(s) instead. Use the captureButtonRenderer prop and pass in a stateless component.

import React from 'react';
import Camera from 'react-dom-camera';

const CoolButton = ({ onClick }) => (
  <button onClick={onClick} type="button">
    Take photo
  </button>
);

const App = () => (
  <Camera
    captureButtonRenderer={onClick => <CoolButton onClick={onClick} />}
    onTakePhoto={image =>
      console.log(image, 'do whatever you want with the image')
    }
  />
);

Props

Property Type Default Description
captureButtonRenderer function undefined Renders a custom capture button that is used to take the photo.
facingMode string ENVIRONMENT The default facing mode to use, E.g. Environment or User.
height number undefined The ideal height of the video.
onStopMediaStream function undefined This function is called when the video stops streaming.
onTakePhoto function undefined This function is called when the capture button is pressed. The captured image is passed as an argument here.
responsive boolean true Applies width: 100% to the video element so it fills the container it's in.
width number undefined The ideal width of the video.

Browser support

๐Ÿ”— caniuse.com

react-camera's People

Contributors

arjanj 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.