1.1.5 • Published 2 years ago

@squads-fabrica-software/react-camera v1.1.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@squads-fabrica-software/react-camera

Read this in Brazilian Portuguese (PT-BR): Português.

This is Camera component for React

Requirements

  • react >= 16.8.0
  • react-dom >= 16.8.0

Instalation

npm install --save @squads-fabrica-software/react-camera
yarn add @squads-fabrica-software/react-camera

Getting started

Usage

Simple usage:

import React from "react";
import { Camera } from "@squads-fabrica-software/react-camera";

function App() {
  return (
    <div>
      <Camera />
    </div>
  );
}

All props usage:

import React from "react";
import { Camera } from "@squads-fabrica-software/react-camera";

function App() {
  return (
    <Camera
      onCameraStart={(mediaStream) => handleCameraStart(mediaStream)}
      onCameraError={(error) => handleCameraError(error)}
      onScreenshot={(data) => handleScreenshot(data)}
      idealFacingMode="user"
      idealResolution="1920x1080"
      minResolution="640x480"
      width={600}
      maxWidth={600}
      height="auto"
      maxHeight="auto"
      cropToFit="3:4"
      overlayImage={IMAGE_URL}
      overlayAlt="Overlay image"
      overlayHeight={400}
      overlayWidth={300}
      overlayPosition="center"
      mirrorImage={true}
    />
  );
}

API

Parameters accepted

PropertyTypeDefaultDescription
onCameraStart():EventCallback called when the camera is successfully started. Returns the media stream object.
onCameraError():EventCallback called when there's an error while opening the camera. Returns the error.
onScreenshot():EventCallback called when a screenshot is taken. Returns a base 64 string of the screenshot image.
idealFacingModeStringBrowser defaultThe ideal facing mode of the camera: environment (usually the back camera) or user (usually the front camera).
idealResolutionString1920x1080The ideal resolution for the camera. Format 999x999.
minResolutionString640x480The minimun allowed resolution for the camera. Format 999x999.
widthNumber or "100%" or "auto""100%"Width of the camera.
maxWidthNumber or "100%" or "auto""100%"Maximum width of the camera.
heightNumber or "100%" or "auto""100%"Height of the camera.
maxHeightNumber or "100%" or "auto"Maximum height of the camera.
cropToFit"3:4"Centers and crops the camera to a 3:4 resolution based on the provived numeric width.
overlayImageImage URLPlaces the provived overlay image on top of the camera with position absolute.
overlayAltStringEmpty stringText to be inserted into the alt attribute of the overlay image tag.
overlayWidthNumber or "100%""100%"Width of the overlay image.
overlayHeightNumber or "100%""100%"Height of the overlay image.
overlayPosition"center" or "cover""cover"On "center" it centers the image with top and left 50%, on "cover" it places the image with top and left 0.
mirrorImagebooleantrueMirror video image.

CropToFit

This feature aims to crop cameras with other resolutions to 3:4 resolution. For example, if you're on desktop with a webcam that has a landscape orientation and you want it to be on 3:4. The video player will center and hide the rest of the video player that overflows the 3:4 resolution. The image screenshot will also be cropped accordingly.

3:4 is the only resolution supported at the moment. Hopefully we'll be able to support other resolutions in the future.

1.1.5

2 years ago

1.1.4

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago