Giter Club home page Giter Club logo

camtest's Introduction

<style media="screen">
  html, body{
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
}
#camera, #camera--view, #camera--sensor, #camera--output{
    position: fixed;
    height: 200px;
    width: 200px;
   
}
#camera--output{
     position : relative;
     display: none;
}

#camera--view, #camera--sensor, #camera--output{
    transform: scaleX(-1);
    filter: FlipH;
}
#camera--trigger {
    display: none;
    position: relative;
    width: 99%;
    height: 99%;
}
#camera--trigger:before {
    display: block;
    content: "";
    width: 20px;
    height: 20px;
    position: absolute;
    top: 1px;
    left: 1px;
    border-top: 4px solid #bc0c0c;
    border-left: 4px solid #bc0c0c;
    margin-left: 33px;
    margin-top: 30px;
    z-index: 10;
}
#camera--trigger:after {
    display: block;
    content: "";
    width: 20px;
    height: 20px;
    position: absolute;
    top: 1px;
    right: 1px;
    border-top: 4px solid #bc0c0c;
    border-right: 4px solid #bc0c0c;
    margin-right: 50px;
    margin-top: 30px;
    z-index: 10;
}
#camera--trigger span:before {
    display: block;
    content: "";
    width: 20px;
    height: 20px;
    position: absolute;
    bottom: 1px;
    left: 1px;
    border-bottom: 4px solid #bc0c0c;
    border-left: 4px solid #bc0c0c;
    margin-left: 33px;
    margin-bottom: 20px;
    margin-right: 40px;
    z-index: 10;
}
#camera--trigger span:after {
    display: block;
    content: "";
    width: 20px;
    height: 20px;
    position: absolute;
    bottom: 1px;
    right: 1px;
    border-bottom: 4px solid #bc0c0c;
    border-right: 4px solid #bc0c0c;
    margin-left: 33px;
    margin-bottom: 20px;
    margin-right: 50px;
    z-index: 10;
}

.taken{
    transition: all 0.5s ease-in;
    height: 150px !important;
    margin-top: 6px;
}
</style>
Take a picture
    </div>


</main>
<!-- Reference to your JavaScript file -->
<script>
    // Set constraints for the video stream
    //var constraints = { video: { facingMode: "user" }, audio: false };
    //var constraints = { video: { facingMode: "user" }, audio: false };
    
    var constraints = { video: { facingMode: "environment"  }, audio: false };
    
    // Define constants
    const cameraView = document.querySelector("#camera--view"),
        cameraOutput = document.querySelector("#camera--output"),
        cameraSensor = document.querySelector("#camera--sensor"),
        cameraTrigger = document.querySelector("#camera--trigger")
    // Access the device camera and stream to cameraView
    function cameraStart() {
        const supported = 'mediaDevices' in navigator;
        if (!supported) {
            alert('device not supported')
            return;
        }
        navigator.mediaDevices
            .getUserMedia(constraints)
            .then(function(stream) {
                cameraTrigger.style.display = 'block';
                track = stream.getTracks()[0];
                cameraView.srcObject = stream;
            })
            .catch(function(error) {
                alert('Cant start');
                console.error("Oops. Something is broken.", error);
            });
    }
    // Take a picture when cameraTrigger is tapped
    cameraTrigger.onclick = function() {
        cameraSensor.width = cameraView.videoWidth;
        cameraSensor.height = cameraView.videoHeight;
        cameraSensor.getContext("2d").drawImage(cameraView, 0, 0);
        cameraOutput.src = cameraSensor.toDataURL("image/webp");
        cameraOutput.classList.add("taken");

        cameraView.srcObject.getVideoTracks().forEach(track => track.stop());
        cameraSensor.style.display = 'none';
        //cameraView.style.display = 'none';
        cameraOutput.style.display = 'block';

    };
    // Start the video stream when the window loads
    window.addEventListener("load", cameraStart, false);
</script>

camtest's People

Contributors

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