GithubHelp home page GithubHelp logo

vue-snapster's Introduction

Vue Camera

Customizable camera library for Vue 3, within asking permission to user.

Features

  • Asking Permission to user
  • Flip camera rear/front
  • Result blob/b64
  • Mirror Camera

Installation

npm i @malbuf/vue-snapster

Usage

To use it in your Vue app

First, import in your custom component for proxy camera

import VxCamera from "@malbuf/vue-snapster"

Second, create ref for canvas and video:

  • video for camera places
  • canvas for result after camera taken
const videoRef = ref<HTMLVideoElement>();
const canvasRef = ref<HTMLCanvasElement>();

Third, create variable to memoize your camera instance

const cameraRef = ref();

Fourth, create an function for starting camera

example:

const permissionDenied = ref(false);
const isCameraOpen = ref(false);

async function startCamera () {

    const checkPermission = setInterval(() => {
        if (isCameraOpen.value) {
        clearInterval(checkPermission);
        } else {
        permissionDenied.value = true;
        clearInterval(checkPermission);
        }
    }, 1000);

    cameraRef.value = await new VxCamera(videoRef.value!, canvasRef.value!)
            .setConstraint({
                video: {
                    facingMode: "environment",
                    height: {
                    min: 480,
                    max: 480,
                    ideal: 480,
                    },
                    width: {
                    min: 480,
                    max: 480,
                    ideal: 480,
                    },
                },
                audio: false,
            })
            .requestPermission()
            .then((camera) => camera)
            .catch((err) => {
                console.error(err);
            });

    cameraRef.value?.start().finally(() => (isCameraOpen.value = true));
}

Fifth, taking a picture and save as blob/b64

const result = await cameraRef.value?.snapAsBlob().then((data: any) => data)
// or
const result = await cameraRef.value?.snapAsBase64().then((data: any) => data)

snapAsBase64 or snapAsBlob

That was example using the library to your project.

Contributing

Contributions are always welcome! Feel free to fork the repository and submit pull requests.

Issues

If you find any bug or have a feature request, please file an issue on Github.


Happy Developing!

vue-snapster's People

Contributors

malabudif avatar

Watchers

 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.